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(std/encoding/toml): could not parse strings with apostrophes/semicolons #6781

Merged
merged 3 commits into from
Jul 16, 2020
Merged

fix(std/encoding/toml): could not parse strings with apostrophes/semicolons #6781

merged 3 commits into from
Jul 16, 2020

Conversation

uki00a
Copy link
Contributor

@uki00a uki00a commented Jul 16, 2020

This PR fixes #6776.

Cause

This bug is caused by a regular expression used to delete TOML comments.
Before this fix, TOML comments were stripped down by the following code:

    const m = /(?:\'|\[|{|\").*(?:\'|\]|\"|})\s*[^#]/g.exec(dataString);
    if (m) {
      dataString = m[0].trim();
    }

However, this regular expression does not properly handle strings containing apostrophes/semicolons:

/(?:\'|\[|{|\").*(?:\'|\]|\"|})\s*[^#]/g.exec(`"What if it's not?"`); // => [ `"What if it's` ]

/(?:\'|\[|{|\").*(?:\'|\]|\"|})\s*[^#]/g.exec(`"const message = 'hello world';"`); // => [ `"const message = 'hello world';` ]

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks!

@ry ry merged commit 121eaa4 into denoland:master Jul 16, 2020
@uki00a uki00a deleted the issue-6776 branch July 16, 2020 23:38
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(std/encoding) TOML parser throws SyntaxError: Invalid or unexpected token
2 participants