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

Post.js doesn't escape data with double quote characters #4142

Open
smroe opened this issue Feb 21, 2020 · 2 comments
Open

Post.js doesn't escape data with double quote characters #4142

smroe opened this issue Feb 21, 2020 · 2 comments

Comments

@smroe
Copy link

@smroe smroe commented Feb 21, 2020

Expected behaviour

Import of xml2js file (created from Joomla site) to create a set of .md files representing the origin Joomla site.

Actual behavior

YAML processing exception thrown:
YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 2, column 5:
date: 2011-11-14 14:38:13
^
at generateError (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:167:10)
at throwError (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:173:9)
at readBlockMapping (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:1073:9)
at composeNode (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:1359:12)
at readDocument (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:1519:3)
at loadDocuments (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:1575:5)
at load (<>\import\node_modules\js-yaml\lib\js-yaml\loader.js:1596:19)
at _getScaffold.then.then.frontMatter (<>\import\node_modules\hexo\lib\hexo\post.js:149:63)
at tryCatcher (<>\import\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (<>\import\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (<>\import\node_modules\bluebird\js\release\promise.js:604:18)

Possible Solution

I have traced this and think that the problem is in post.js @ PostRenderCache.prepareFrontMatter. The current string case assumes that the item variable doesn't include any double quotation marks. If it does, then the resulting data[key] value has an incorrect format.

I don't know if this will impact elsewhere, but I think that the last case needs to be modified to:

for (const key of Object.keys(data)) {
    const item = data[key];

    if (moment.isMoment(item)) {
      data[key] = item.utc().format('YYYY-MM-DD HH:mm:ss');
    } else if (moment.isDate(item)) {
      data[key] = moment.utc(item).format('YYYY-MM-DD HH:mm:ss');
    } else if (typeof item === 'string') {
      data[key] = `"` + item.replace( /"/g, '\\"')  + `"`;
    }
  }

  return data;
@SukkaW

This comment has been minimized.

Copy link
Member

@SukkaW SukkaW commented Feb 21, 2020

Would you mind providing me about the exact front-matter of your markdown file?

@smroe

This comment has been minimized.

Copy link
Author

@smroe smroe commented Feb 21, 2020

The problem occurs when using the Joomla migrator, so you need to use an xml2js file. Mine is 100+Meg in size, so I have distilled it into a single article (at a much more friendly 2k).

Migrating the attachment, via:

hexo migrate joomla input.xml

results in the exception. Escaping the " characters in the title (via the above adjustment) sorts the problem.
input.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.