Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/regexp/regexp-parser.cc

Issue 2795093003: [regexp] Disallow '\' in capture names (Closed)
Patch Set: Also fix ID_Continue Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/regexp-named-captures.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/regexp/regexp-parser.h" 5 #include "src/regexp/regexp-parser.h"
6 6
7 #include "src/char-predicates-inl.h" 7 #include "src/char-predicates-inl.h"
8 #include "src/factory.h" 8 #include "src/factory.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 if (c == '\\' && current() == 'u') { 782 if (c == '\\' && current() == 'u') {
783 // TODO(jgruber): Reconsider this once the spec has settled. 783 // TODO(jgruber): Reconsider this once the spec has settled.
784 // https://github.com/tc39/proposal-regexp-named-groups/issues/23 784 // https://github.com/tc39/proposal-regexp-named-groups/issues/23
785 Advance(); 785 Advance();
786 if (!ParseUnicodeEscape(&c)) { 786 if (!ParseUnicodeEscape(&c)) {
787 ReportError(CStrVector("Invalid Unicode escape sequence")); 787 ReportError(CStrVector("Invalid Unicode escape sequence"));
788 return nullptr; 788 return nullptr;
789 } 789 }
790 } 790 }
791 791
792 // The backslash char is misclassified as both ID_Start and ID_Continue.
793 if (c == '\\') {
794 ReportError(CStrVector("Invalid capture group name"));
795 return nullptr;
796 }
797
792 if (at_start) { 798 if (at_start) {
793 if (!IdentifierStart::Is(c)) { 799 if (!IdentifierStart::Is(c)) {
794 ReportError(CStrVector("Invalid capture group name")); 800 ReportError(CStrVector("Invalid capture group name"));
795 return nullptr; 801 return nullptr;
796 } 802 }
797 push_code_unit(name, c); 803 push_code_unit(name, c);
798 at_start = false; 804 at_start = false;
799 } else { 805 } else {
800 if (c == '>') { 806 if (c == '>') {
801 break; 807 break;
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 return false; 1870 return false;
1865 } 1871 }
1866 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom), 1872 terms_.Add(new (zone()) RegExpQuantifier(min, max, quantifier_type, atom),
1867 zone()); 1873 zone());
1868 LAST(ADD_TERM); 1874 LAST(ADD_TERM);
1869 return true; 1875 return true;
1870 } 1876 }
1871 1877
1872 } // namespace internal 1878 } // namespace internal
1873 } // namespace v8 1879 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/regexp-named-captures.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698