Skip to content

Commit

Permalink
fix(h5p-html-exporter): turkish characters in current working dir work (
Browse files Browse the repository at this point in the history
  • Loading branch information
sr258 authored Aug 31, 2021
1 parent 7a2a028 commit 9632877
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions packages/h5p-html-exporter/src/HtmlExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,25 +443,43 @@ export default class HtmlExporter {
}),
postCssClean()
);

let oldCwd;
try {
processedCss = (
await pCss.process(licenseText + text, {
from: filename
})
)?.css;
} catch (error) {
// We retry with a more tolerant CSS parser if parsing has
// failed with the regular one.
if (error instanceof CssSyntaxError) {
// This is a workaround for a bug in path.relative in
// Windows. If the current working directory includes the
// Turkish İ character, the resulting relative path is
// broken. We work around this by temporarily changing the
// working directory to the root. See
// https://github.com/Lumieducation/H5P-Nodejs-library/issues/1679#issuecomment-909344236
if (process.platform === 'win32') {
oldCwd = process.cwd();
process.chdir('c:');
}

try {
processedCss = (
await pCss.process(licenseText + text, {
parser: postCssSafeParser,
from: filename
})
)?.css;
} else {
throw error;
} catch (error) {
// We retry with a more tolerant CSS parser if parsing has
// failed with the regular one.
if (error instanceof CssSyntaxError) {
processedCss = (
await pCss.process(licenseText + text, {
parser: postCssSafeParser,
from: filename
})
)?.css;
} else {
throw error;
}
}
} finally {
// Part of the workaround explained above.
if (process.platform === 'win32' && oldCwd) {
process.chdir(oldCwd);
}
}
styleTexts[style] = processedCss;
Expand Down

0 comments on commit 9632877

Please sign in to comment.