Changeset 86547 in webkit


Ignore:
Timestamp:
May 16, 2011 2:08:07 AM (13 years ago)
Author:
barraclough@apple.com
Message:

https://bugs.webkit.org/show_bug.cgi?id=60866
Evaluation order broken for empty alternatives in subpatterns

Rubber stamped by Geoff Garen.

Source/JavaScriptCore:

Reverting https://bugs.webkit.org/show_bug.cgi?id=51395

  • yarr/YarrPattern.cpp:

(JSC::Yarr::YarrPatternConstructor::atomParenthesesEnd):

LayoutTests:

Reverted https://bugs.webkit.org/show_bug.cgi?id=51395, and added
test cases for /(|a)/ and /(a|)/, to test the evaluation order of
subpattern matches with empty alternatives.

  • fast/regex/parentheses-expected.txt:
  • fast/regex/script-tests/parentheses.js:
  • fast/regex/script-tests/slow.js:
  • fast/regex/slow-expected.txt:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r86546 r86547  
     12011-05-16  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Rubber stamped by Geoff Garen.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=60866
     6        Evaluation order broken for empty alternatives in subpatterns
     7
     8        Reverted https://bugs.webkit.org/show_bug.cgi?id=51395, and added
     9        test cases for /(|a)/ and /(a|)/, to test the evaluation order of
     10        subpattern matches with empty alternatives.
     11
     12        * fast/regex/parentheses-expected.txt:
     13        * fast/regex/script-tests/parentheses.js:
     14        * fast/regex/script-tests/slow.js:
     15        * fast/regex/slow-expected.txt:
     16
    1172011-05-16  Alejandro G. Castro  <alex@igalia.com>
    218
  • trunk/LayoutTests/fast/regex/parentheses-expected.txt

    r86536 r86547  
    9292PASS regexp54.exec('#') is ['','',undefined,undefined,'']
    9393PASS regexp55.exec('#') is ['','']
     94PASS regexp56.exec('a') is ['','']
     95PASS regexp57.exec('a') is ['a','a']
    9496PASS successfullyParsed is true
    9597
  • trunk/LayoutTests/fast/regex/script-tests/parentheses.js

    r86536 r86547  
    241241shouldBe("regexp55.exec('#')", "['','']");
    242242
     243// Test evaluation order of empty subpattern alternatives.
     244var regexp56 = /(|a)/;
     245shouldBe("regexp56.exec('a')", "['','']");
     246var regexp57 = /(a|)/;
     247shouldBe("regexp57.exec('a')", "['a','a']");
     248
    243249var successfullyParsed = true;
    244250
  • trunk/LayoutTests/fast/regex/script-tests/slow.js

    r76502 r86547  
    33);
    44
    5 shouldBe('/(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/")', 'true');
     5shouldBe('/(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/")', 'false');
    66
    77var successfullyParsed = true;
  • trunk/LayoutTests/fast/regex/slow-expected.txt

    r76502 r86547  
    44
    55
    6 PASS /(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/") is true
     6PASS /(?:[^(?!)]||){23}z/.test("/(?:[^(?!)]||){23}z/") is false
    77PASS successfullyParsed is true
    88
  • trunk/Source/JavaScriptCore/ChangeLog

    r86536 r86547  
     12011-05-16  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Rubber stamped by Geoff Garen.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=60866
     6        Evaluation order broken for empty alternatives in subpatterns
     7
     8        Reverting https://bugs.webkit.org/show_bug.cgi?id=51395
     9
     10        * yarr/YarrPattern.cpp:
     11        (JSC::Yarr::YarrPatternConstructor::atomParenthesesEnd):
     12
    1132011-05-15  Gavin Barraclough  <barraclough@apple.com>
    214
  • trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp

    r80217 r86547  
    492492        unsigned numParenAlternatives = parenthesesDisjunction->m_alternatives.size();
    493493        unsigned numBOLAnchoredAlts = 0;
    494         bool containsEmptyAlternative = false;
    495494
    496495        for (unsigned i = 0; i < numParenAlternatives; i++) {
    497             if (!parenthesesDisjunction->m_alternatives[i]->m_terms.size() && numParenAlternatives > 1) {
    498                 PatternAlternative* altToRemove = parenthesesDisjunction->m_alternatives[i];
    499                 parenthesesDisjunction->m_alternatives.remove(i);
    500                 delete altToRemove;
    501                 --numParenAlternatives;
    502 
    503                 containsEmptyAlternative = true;
    504                 continue;
    505             }
    506 
    507496            // Bubble up BOL flags
    508497            if (parenthesesDisjunction->m_alternatives[i]->m_startsWithBOL)
     
    519508        lastTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
    520509        m_invertParentheticalAssertion = false;
    521 
    522         if (containsEmptyAlternative) {
    523             // Backup and remove the current disjunction's alternatives.
    524             Vector<PatternAlternative*> alternatives;
    525             alternatives.append(parenthesesDisjunction->m_alternatives);
    526             parenthesesDisjunction->m_alternatives.clear();
    527             PatternAlternative* alternative = parenthesesDisjunction->addNewAlternative();
    528 
    529             // Insert a new non-capturing parentheses.
    530             unsigned subpatternId = m_pattern.m_numSubpatterns + 1;
    531             PatternDisjunction* newDisjunction = new PatternDisjunction(alternative);
    532             m_pattern.m_disjunctions.append(newDisjunction);
    533             alternative->m_terms.append(PatternTerm(PatternTerm::TypeParenthesesSubpattern, subpatternId, newDisjunction, false, false));
    534             newDisjunction->m_alternatives.append(alternatives);
    535 
    536             // Set the quantifier of the new parentheses to '?' and set the inherited properties.
    537             PatternTerm& disjunctionTerm = alternative->lastTerm();
    538             disjunctionTerm.quantify(1, QuantifierGreedy);
    539             disjunctionTerm.parentheses.lastSubpatternId = m_pattern.m_numSubpatterns;
    540             alternative->m_containsBOL = m_alternative->m_containsBOL;
    541             alternative->m_startsWithBOL = m_alternative->m_startsWithBOL;
    542         }
    543510    }
    544511
Note: See TracChangeset for help on using the changeset viewer.