From 4a725b7ac5ec983a2efcd8bb3c3786beab175b61 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 17 Nov 2012 21:31:52 -0500 Subject: [PATCH] Fix another couple bugs regarding template contexts and verify_safe(). --- mwparserfromhell/parser/tokenizer.c | 18 +++++++++++++++--- mwparserfromhell/parser/tokenizer.h | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/mwparserfromhell/parser/tokenizer.c b/mwparserfromhell/parser/tokenizer.c index 0016515..57c6a62 100644 --- a/mwparserfromhell/parser/tokenizer.c +++ b/mwparserfromhell/parser/tokenizer.c @@ -1153,18 +1153,30 @@ Tokenizer_verify_safe(Tokenizer* self, int context, Py_UNICODE data) self->topstack->context |= LC_FAIL_NEXT; return; } + if (data == *"|") { + if (context & LC_FAIL_ON_TEXT) { + self->topstack->context ^= LC_FAIL_ON_TEXT; + return; + } + } } else if (context & (LC_TEMPLATE_PARAM_KEY | LC_ARGUMENT_NAME)) { - if (context & LC_FAIL_ON_LBRACE) { - if (data == *"{") { + if (context & LC_FAIL_ON_EQUALS) { + if (data == *"=") { self->topstack->context |= LC_FAIL_NEXT; return; } + } + else if (context & LC_FAIL_ON_LBRACE) { + if (data == *"{") { + self->topstack->context |= (context & LC_TEMPLATE) ? LC_FAIL_ON_EQUALS : LC_FAIL_NEXT; + return; + } self->topstack->context ^= LC_FAIL_ON_LBRACE; } else if (context & LC_FAIL_ON_RBRACE) { if (data == *"}") { - self->topstack->context |= LC_FAIL_NEXT; + self->topstack->context |= (context & LC_TEMPLATE) ? LC_FAIL_ON_EQUALS : LC_FAIL_NEXT; return; } self->topstack->context ^= LC_FAIL_ON_RBRACE; diff --git a/mwparserfromhell/parser/tokenizer.h b/mwparserfromhell/parser/tokenizer.h index 67c39cd..2484d4f 100644 --- a/mwparserfromhell/parser/tokenizer.h +++ b/mwparserfromhell/parser/tokenizer.h @@ -119,6 +119,7 @@ static PyObject* TagCloseClose; #define LC_FAIL_NEXT 0x10000 #define LC_FAIL_ON_LBRACE 0x20000 #define LC_FAIL_ON_RBRACE 0x40000 +#define LC_FAIL_ON_EQUALS 0x80000 /* Global contexts: */