[Pkg-javascript-commits] [node-acorn-jsx] 166/484: Make sure syntax errors in regular expressions raise conforming exceptions
Bastien Roucariès
rouca at moszumanska.debian.org
Sat Aug 19 14:20:20 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 baaa16cee7aa78cfd8ec4167bc1c1e20f7d319bb
Author: Marijn Haverbeke <marijnh at gmail.com>
Date: Wed Nov 20 10:56:28 2013 +0100
Make sure syntax errors in regular expressions raise conforming exceptions
Just letting the error from new RegExp through creates an exception missing the
pos/loc/raisedAt properties.
Issue #82
Issue #81
---
acorn.js | 8 +++++++-
index.html | 8 +++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/acorn.js b/acorn.js
index e03f6f2..ec3d4ed 100644
--- a/acorn.js
+++ b/acorn.js
@@ -767,7 +767,13 @@
// here (don't ask).
var mods = readWord1();
if (mods && !/^[gmsiy]*$/.test(mods)) raise(start, "Invalid regexp flag");
- return finishToken(_regexp, new RegExp(content, mods));
+ try {
+ var value = new RegExp(content, mods);
+ } catch (e) {
+ if (e instanceof SyntaxError) raise(start, e.message);
+ raise(e);
+ }
+ return finishToken(_regexp, value);
}
// Read an integer in the given radix. Return null if zero digits
diff --git a/index.html b/index.html
index 8b53efc..9c86b83 100644
--- a/index.html
+++ b/index.html
@@ -532,7 +532,13 @@ since a '/' inside a '[]' set does not end the expression.</p> </td>
<span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-70"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-70">¶</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">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_regexp</span><span class="p">,</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="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="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>
<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>Read an integer in the given radix. Return null if zero digits
were read, the integer value otherwise. When <code>len</code> is given, this
will return <code>null</code> unless the integer has exactly <code>len</code> digits.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">readInt</span><span class="p">(</span><span class="nx">radix</span><span class="p">,</span> <span class="nx">len</span><span class="p">)</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