summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2012-03-20 00:46:45 +0100
committerYves Orton <demerphq@gmail.com>2012-03-20 11:20:06 +0100
commita40630bf5c45bc9d528e1eacffde2666ad23c6b2 (patch)
tree1e6f4a74c3ded41955126c6752b7516de7a9d1f6
parent39ea6a4bb86bea2953fbe16b8063fd13073507a0 (diff)
downloadperl-a40630bf5c45bc9d528e1eacffde2666ad23c6b2.tar.gz
[RT #111842] prevent TRIE overwriting EXACT following NOTHING at start
Fixes RT #111842. Example: "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/ Should match, but didn't due to allowing NOTHING to start a sequence. See comment in patch for details. This also changes a test to no longer be TODO, and improves the test name to explain its purpose.
-rw-r--r--regcomp.c22
-rw-r--r--t/re/pat_advanced.t6
2 files changed, 19 insertions, 9 deletions
diff --git a/regcomp.c b/regcomp.c
index 8c287bfba9..70d6c3b38a 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -3325,11 +3325,23 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
if ( noper_trietype
&&
(
- ( noper_trietype == NOTHING )
- ||
- ( trietype == NOTHING )
- ||
- ( trietype == noper_trietype )
+ /* XXX: Currently we cannot allow a NOTHING node to be the first element
+ * of a TRIEABLE sequence, Otherwise we will overwrite the regop following
+ * the NOTHING with the TRIE regop later on. This is because a NOTHING node
+ * is only one regnode wide, and a TRIE is two regnodes. An example of a
+ * problematic pattern is: "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/
+ * At a later point of time we can somewhat workaround this by handling
+ * NOTHING -> EXACT sequences as generated by /(?:)A|(?:)B/ type patterns,
+ * as we can effectively ignore the NOTHING regop in that case.
+ * This clause, which allows NOTHING to start a sequence is left commented
+ * out as a reference.
+ * - Yves
+
+ ( noper_trietype == NOTHING)
+ || ( trietype == NOTHING )
+ */
+ ( noper_trietype == NOTHING && trietype )
+ || ( trietype == noper_trietype )
)
#ifdef NOJUMPTRIE
&& noper_next == tail
diff --git a/t/re/pat_advanced.t b/t/re/pat_advanced.t
index 775f663b34..15f25b59a2 100644
--- a/t/re/pat_advanced.t
+++ b/t/re/pat_advanced.t
@@ -2069,10 +2069,8 @@ EOP
like("\xC0", $p, "Verify \"\\xC0\" =~ /[\\xE0_]/i; pattern in utf8");
}
- {
- local $::TODO = 'RT #111842';
- ok "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/, "EXACT nodetypes";
- }
+ ok "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/,
+ "Check TRIE does not overwrite EXACT following NOTHING at start - RT #111842";
#
# Keep the following tests last -- they may crash perl