Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(routes/pdf): limit outputEncoding qs params to poppler charsets #1353

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/plugins/pdf-to-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ async function plugin(server, options) {
* Remove excess title and meta elements left behind by Poppler;
* Poppler appends `-html` to the file name
*/
const dom = new JSDOM(
await fs.readFile(`${tempFile}-html.html`, {
encoding: config.pdfToHtmlOptions.outputEncoding,
})
);
const dom = new JSDOM(await fs.readFile(`${tempFile}-html.html`));
const titles = dom.window.document.querySelectorAll("title");

// Overwrite title set by Poppler, which reveals directories
Expand Down
26 changes: 25 additions & 1 deletion src/routes/pdf/html/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,31 @@ const pdfToHtmlPostSchema = {
S.string()
.default("UTF-8")
.description("Sets the encoding to use for text output")
.pattern(/^[-\w]+$/m)
// Encodings supported by Poppler
.enum([
"ASCII7",
"Big5",
"Big5ascii",
"EUC-CN",
"EUC-JP",
"GBK",
"ISO-2022-CN",
"ISO-2022-JP",
"ISO-2022-KR",
"ISO-8859-6",
"ISO-8859-7",
"ISO-8859-8",
"ISO-8859-9",
"KOI8-R",
"Latin1",
"Latin2",
"Shift-JIS",
"TIS-620",
"UTF-8",
"UTF-16",
"Windows-1255",
"ZapfDingbats",
])
)
.prop(
"ownerPassword",
Expand Down
26 changes: 25 additions & 1 deletion src/routes/pdf/txt/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,31 @@ const pdfToTxtPostSchema = {
S.string()
.default("UTF-8")
.description("Sets the encoding to use for text output")
.pattern(/^[-\w]+$/m)
// Encodings supported by Poppler
.enum([
"ASCII7",
"Big5",
"Big5ascii",
"EUC-CN",
"EUC-JP",
"GBK",
"ISO-2022-CN",
"ISO-2022-JP",
"ISO-2022-KR",
"ISO-8859-6",
"ISO-8859-7",
"ISO-8859-8",
"ISO-8859-9",
"KOI8-R",
"Latin1",
"Latin2",
"Shift-JIS",
"TIS-620",
"UTF-8",
"UTF-16",
"Windows-1255",
"ZapfDingbats",
])
)
.prop(
"ownerPassword",
Expand Down