[Pkg-javascript-commits] [node-acorn-jsx] 179/484: Prevent loose parser from tripping on invalid regexps
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:23 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-acorn-jsx.
commit 4869ccfa55121ba707cefacde4af701c49383156
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Tue Mar 25 17:45:58 2014 +0100
Prevent loose parser from tripping on invalid regexps
Issue #39
---
acorn.js | 4 ++--
acorn_loose.js | 2 ++
index.html | 4 ++--
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/acorn.js b/acorn.js
index 63abcce..31935f4 100644
--- a/acorn.js
+++ b/acorn.js
@@ -773,11 +773,11 @@
// Need to use `readWord1` because '\uXXXX' sequences are allowed
// here (don't ask).
var mods = readWord1();
- if (mods && !/^[gmsiy]*$/.test(mods)) raise(start, "Invalid regexp flag");
+ if (mods && !/^[gmsiy]*$/.test(mods)) raise(start, "Invalid regular expression flag");
try {
var value = new RegExp(content, mods);
} catch (e) {
- if (e instanceof SyntaxError) raise(start, e.message);
+ if (e instanceof SyntaxError) raise(start, "Error parsing regular expression: " + e.message);
raise(e);
}
return finishToken(_regexp, value);
diff --git a/acorn_loose.js b/acorn_loose.js
index 79cc15f..1c6fb46 100644
--- a/acorn_loose.js
+++ b/acorn_loose.js
@@ -106,6 +106,8 @@
} else if (/unexpected character/i.test(msg)) {
pos++;
replace = false;
+ } else if (/regular expression/i.test(msg)) {
+ replace = true;
} else {
throw e;
}
diff --git a/index.html b/index.html
index edbc4ca..0e2d6e6 100644
--- a/index.html
+++ b/index.html
@@ -536,11 +536,11 @@ since a '/' inside a '[]' set does not end the expression.</p> </td>
<span class="kd">var</span> <span class="nx">content</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="nx">tokPos</span><span class="p">);</span>
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-71"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-71">¶</a> </div> <p>Need to use <code>readWord1</code> because '\uXXXX' sequences are allowed
here (don't ask).</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">mods</span> <span class="o">=</span> <span class="nx">readWord1</span><span class="p">();</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">mods</span> <span class="o">&&</span> <span class="o">!</span><span class="sr">/^[gmsiy]*$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">mods</span><span class="p">))</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Invalid regexp flag"</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">mods</span> <span class="o">&&</span> <span class="o">!</span><span class="sr">/^[gmsiy]*$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">mods</span><span class="p">))</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Invalid regular expression flag"</span><span class [...]
<span class="k">try</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">value</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">content</span><span class="p">,</span> <span class="nx">mods</span><span class="p">);</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
- <span class="k">if</span> <span class="p">(</span><span class="nx">e</span> <span class="k">instanceof</span> <span class="nx">SyntaxError</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="nx">e</span><span class="p">.</span><span class="nx">message</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">e</span> <span class="k">instanceof</span> <span class="nx">SyntaxError</span><span class="p">)</span> <span class="nx">raise</span><span class="p">(</span><span class="nx">start</span><span class="p">,</span> <span class="s2">"Error parsing regular expression: "</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">message</span><span class="p">);</span>
<span class="nx">raise</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_regexp</span><span class="p">,</span> <span class="nx">value</span><span class="p">);</span>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git
More information about the Pkg-javascript-commits
mailing list