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

Regular expression literal in JS code can be mis-parsed as unterminated strings #98

Closed
schlessera opened this issue Oct 29, 2018 · 3 comments · Fixed by #99
Closed

Regular expression literal in JS code can be mis-parsed as unterminated strings #98

schlessera opened this issue Oct 29, 2018 · 3 comments · Fixed by #99

Comments

@schlessera
Copy link
Member

schlessera commented Oct 29, 2018

The JavaScript parsing code contains a bug in the upstream mck89/peast library.

If the parsed code has regular expression literals containing quotes, these quotes are erroneously being parsed as opening or closing a string literal.

This will in turn cause the parser to throw an Unterminated string error once it hits the end of the line.

As an example, the WordPress Core code contains regular expression literals like this:

function escapeHTML(s) {
   var n = s;
   n = n.replace(/&/g, '&');
   n = n.replace(/</g, '&lt;');
   n = n.replace(/>/g, '&gt;');
   n = n.replace(/"/g, '&quot;');

   return n;
}

In this example, the regular expression literal /"/g will be parsed as opening a double-quoted string and throw an error once it hits the next line.

@schlessera
Copy link
Member Author

After some discussion on Slack, we opted to use a work-around in wp i18n makepot while waiting on the upstream bug to get a fix (which we expect is more involved).

Planned work-around is to string-replace away the offending regular expression literals in the in-memory file representation that the peast library works off of.

@schlessera
Copy link
Member Author

Maybe we should keep this open until the upstream bug is fixed.

@schlessera
Copy link
Member Author

We should look into this again, as the upstream issue seems to have been fixed: mck89/peast#3

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

Successfully merging a pull request may close this issue.

1 participant