Changeset 18182 in webkit
- Timestamp:
- Dec 12, 2006 12:09:58 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r18170 r18182 1 2006-12-12 Alexey Proskuryakov <ap@webkit.org> 2 3 Reviewed by Geoff. Based on a patch by Maks Orlovich. 4 5 http://bugs.webkit.org/show_bug.cgi?id=6257 6 Throw errors on invalid expressions (KJS merge) 7 8 * kjs/regexp.cpp: 9 (KJS::RegExp::RegExp): 10 (KJS::RegExp::~RegExp): 11 (KJS::RegExp::match): 12 * kjs/regexp.h: 13 (KJS::RegExp::flags): 14 (KJS::RegExp::isValid): 15 (KJS::RegExp::errorMessage): 16 (KJS::RegExp::subPatterns): 17 Remember and report RegExp construction failures. Renamed data members not to start with underscores. 18 19 * kjs/regexp_object.cpp: 20 (RegExpObjectImp::construct): Raise an exception if RegExp construction fails. 21 (RegExpObjectImp::callAsFunction): Removed an obsolete comment. 22 23 * tests/mozilla/ecma_3/RegExp/regress-119909.js: Reduced the number of nested parentheses to 24 a value supported by PCRE. 25 1 26 2006-12-11 Alexey Proskuryakov <ap@webkit.org> 2 27 -
trunk/JavaScriptCore/kjs/regexp.cpp
r17862 r18182 2 2 /* 3 3 * This file is part of the KDE libraries 4 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)4 * Copyright (C) 1999-2001,2004 Harri Porten (porten@kde.org) 5 5 * 6 6 * This library is free software; you can redistribute it and/or … … 23 23 #include "regexp.h" 24 24 25 #include "lexer.h" 26 25 27 #include <assert.h> 26 28 #include <stdio.h> … … 31 33 32 34 RegExp::RegExp(const UString &p, int flags) 33 : _flags(flags),_numSubPatterns(0)35 : m_flags(flags), m_constructionError(0), m_numSubPatterns(0) 34 36 { 35 37 #if HAVE(PCREPOSIX) … … 49 51 50 52 pattern.append('\0'); 51 _regex = pcre_compile(reinterpret_cast<const uint16_t*>(pattern.data()),53 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(pattern.data()), 52 54 options, &errorMessage, &errorOffset, NULL); 53 if (! _regex) {55 if (!m_regex) { 54 56 // Try again, this time handle any \u we might find. 55 57 UString uPattern = sanitizePattern(pattern); 56 _regex = pcre_compile(reinterpret_cast<const uint16_t*>(uPattern.data()),58 m_regex = pcre_compile(reinterpret_cast<const uint16_t*>(uPattern.data()), 57 59 options, &errorMessage, &errorOffset, NULL); 58 if (!_regex) 60 if (!m_regex) { 61 m_constructionError = strdup(errorMessage); 59 62 return; 63 } 60 64 } 61 65 62 66 #ifdef PCRE_INFO_CAPTURECOUNT 63 67 // Get number of subpatterns that will be returned. 64 pcre_fullinfo( _regex, NULL, PCRE_INFO_CAPTURECOUNT, &_numSubPatterns);68 pcre_fullinfo(m_regex, NULL, PCRE_INFO_CAPTURECOUNT, &m_numSubPatterns); 65 69 #endif 66 70 … … 81 85 // Note: the Global flag is already handled by RegExpProtoFunc::execute 82 86 83 regcomp(&_regex, p.ascii(), regflags); 84 /* TODO check for errors */ 87 // FIXME: support \u Unicode escapes. 88 89 int errorCode = regcomp(&m_regex, intern.ascii(), regflags); 90 if (errorCode != 0) { 91 char errorMessage[80]; 92 regerror(errorCode, &m_regex, errorMessage, sizeof errorMessage); 93 m_constructionError = strdup(errorMessage); 94 } 85 95 86 96 #endif … … 90 100 { 91 101 #if HAVE(PCREPOSIX) 92 pcre_free( _regex);102 pcre_free(m_regex); 93 103 #else 94 104 /* TODO: is this really okay after an error ? */ 95 regfree(&_regex); 96 #endif 105 regfree(&m_regex); 106 #endif 107 free(m_constructionError); 97 108 } 98 109 … … 113 124 #if HAVE(PCREPOSIX) 114 125 115 if (! _regex)126 if (!m_regex) 116 127 return UString::null(); 117 128 … … 125 136 offsetVector = fixedSizeOffsetVector; 126 137 } else { 127 offsetVectorSize = ( _numSubPatterns + 1) * 3;138 offsetVectorSize = (m_numSubPatterns + 1) * 3; 128 139 offsetVector = new int [offsetVectorSize]; 129 140 } 130 141 131 const int numMatches = pcre_exec( _regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize);142 const int numMatches = pcre_exec(m_regex, NULL, reinterpret_cast<const uint16_t *>(s.data()), s.size(), i, 0, offsetVector, offsetVectorSize); 132 143 133 144 if (numMatches < 0) { … … 152 163 153 164 char *str = strdup(s.ascii()); // TODO: why ??? 154 if (regexec(& _regex, str + i, maxMatch, rmatch, 0)) {165 if (regexec(&m_regex, str + i, maxMatch, rmatch, 0)) { 155 166 free(str); 156 167 return UString::null(); … … 164 175 165 176 // map rmatch array to ovector used in PCRE case 166 _numSubPatterns = 0;177 m_numSubPatterns = 0; 167 178 for(unsigned j = 1; j < maxMatch && rmatch[j].rm_so >= 0 ; j++) 168 _numSubPatterns++;169 int ovecsize = ( _numSubPatterns+1)*3; // see above179 m_numSubPatterns++; 180 int ovecsize = (m_numSubPatterns+1)*3; // see above 170 181 *ovector = new int[ovecsize]; 171 for (unsigned j = 0; j < _numSubPatterns + 1; j++) {182 for (unsigned j = 0; j < m_numSubPatterns + 1; j++) { 172 183 if (j>maxMatch) 173 184 break; -
trunk/JavaScriptCore/kjs/regexp.h
r17862 r18182 46 46 ~RegExp(); 47 47 48 int flags() const { return _flags; } 48 int flags() const { return m_flags; } 49 bool isValid() const { return !m_constructionError; } 50 const char* errorMessage() const { return m_constructionError; } 49 51 50 52 UString match(const UString &s, int i, int *pos = 0, int **ovector = 0); 51 unsigned subPatterns() const { return _numSubPatterns; }53 unsigned subPatterns() const { return m_numSubPatterns; } 52 54 53 55 private: 54 56 #if HAVE(PCREPOSIX) 55 pcre * _regex;57 pcre *m_regex; 56 58 #else 57 regex_t _regex;59 regex_t m_regex; 58 60 #endif 59 int _flags; 60 unsigned _numSubPatterns; 61 int m_flags; 62 char* m_constructionError; 63 unsigned m_numSubPatterns; 61 64 62 65 RegExp(const RegExp &); -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r15846 r18182 383 383 bool ignoreCase = (flags.find("i") >= 0); 384 384 bool multiline = (flags.find("m") >= 0); 385 // TODO: throw a syntax error on invalid flags386 385 387 386 dat->putDirect("global", jsBoolean(global), DontDelete | ReadOnly | DontEnum); … … 399 398 if (multiline) 400 399 reflags |= RegExp::Multiline; 401 dat->setRegExp(new RegExp(p, reflags)); 400 RegExp* re = new RegExp(p, reflags); 401 if (!re->isValid()) { 402 delete re; 403 return throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(re->errorMessage())); 404 } 405 dat->setRegExp(re); 402 406 403 407 return dat; … … 407 411 JSValue *RegExpObjectImp::callAsFunction(ExecState *exec, JSObject * /*thisObj*/, const List &args) 408 412 { 409 // TODO: handle RegExp argument case (15.10.3.1)410 411 413 return construct(exec, args); 412 414 } -
trunk/JavaScriptCore/tests/mozilla/ecma_3/RegExp/regress-119909.js
r11995 r18182 58 58 printStatus(summary); 59 59 60 testThis(500, NO_BACKREFS, 'hello', 'goodbye'); 61 testThis(500, DO_BACKREFS, 'hello', 'goodbye'); 60 // Changed the parameter from 500 to 200 for WebKit, because PCRE reports an error for more parentheses. 61 testThis(200, NO_BACKREFS, 'hello', 'goodbye'); 62 testThis(200, DO_BACKREFS, 'hello', 'goodbye'); 62 63 63 64 exitFunc('test'); -
trunk/LayoutTests/ChangeLog
r18177 r18182 1 2006-12-12 Alexey Proskuryakov <ap@webkit.org> 2 3 Reviewed by Geoff. 4 5 http://bugs.webkit.org/show_bug.cgi?id=6257 6 Throw errors on invalid expressions (KJS merge) 7 8 * fast/js/kde/RegExp-expected.txt: One more test passes. 9 1 10 2006-12-12 Nikolas Zimmermann <zimmermann@kde.org> 2 11 -
trunk/LayoutTests/fast/js/kde/RegExp-expected.txt
r17862 r18182 63 63 PASS 'test1test2'.replace(/(te)(st)/g,'$2$1') is 'stte1stte2' 64 64 PASS 'foo+bar'.replace(/\+/g,'%2B') is 'foo%2Bbar' 65 FAIL caught should be true (of type boolean). Was false (of type boolean). 65 PASS caught is true 66 66 PASS 'foo'.replace(/z?/g,'x') is 'xfxoxox' 67 67 PASS 'test test'.replace(/\s*/g,'') is 'testtest'
Note: See TracChangeset
for help on using the changeset viewer.