]> granicus.if.org Git - multimarkdown/commitdiff
FIXED: Avoid pathologic slowdown on nested brackets
authorFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 29 Jan 2017 13:33:39 +0000 (08:33 -0500)
committerFletcher T. Penney <fletcher@fletcherpenney.net>
Sun, 29 Jan 2017 13:33:39 +0000 (08:33 -0500)
src/writer.c
tools/pathological_tests.sh

index f5b847bfce755cb2cd34bc7f19e4c45df09a87b2..9b60658659830916eee4a0f19e88b38c39a0b464 100644 (file)
@@ -1160,11 +1160,29 @@ void parse_brackets(const char * source, scratch_pad * scratch, token * bracket,
                temp_char = text_inside_pair(source, next);
 
                if (temp_char[0] == '\0') {
-                       // Empty label, use first bracket
+                       // Empty label, use first bracket (e.g. implicit link `[foo][]`)
                        free(temp_char);
                        temp_char = text_inside_pair(source, bracket);
                }
        } else {
+               // This may be a simplified implicit link, e.g. `[foo]`
+
+               // But not if it's nested brackets, since it would not
+               // end up being a valid reference
+               token * walker = bracket->child;
+               while (walker) {
+                       switch (walker->type) {
+                               case PAIR_BRACKET:
+                               case PAIR_BRACKET_CITATION:
+                               case PAIR_BRACKET_FOOTNOTE:
+                               case PAIR_BRACKET_VARIABLE:
+                                       *final_link = NULL;
+                                       return;
+                       }
+
+                       walker = walker->next;
+               }
+
                temp_char = text_inside_pair(source, bracket);
                // Don't skip tokens
                temp_short = 0;
index 329f25d3ce21ccaf9ceeed3df5632a33056509db..72402c07268745179a29d3f322c7825d2e1fada8 100755 (executable)
@@ -76,17 +76,15 @@ echo "**x <a href=\"d\">*b**c*</a></p>" >>  path8.html
 
 
 # Nested brackets
-# TODO: Performance hit between 1000 and 10,000 iterations
-# Checking each level to see if it's a valid link on the stack
-# seq -s " " -f "[" $X >                               path9.text
-# echo -n "a" >>                                               path9.text
-# seq -s " " -f "]" $X >>                              path9.text
-# 
-# echo -n "<p>" >                                              path9.html
-# seq -s " " -f "[" $X >>                              path9.html
-# echo -n "a" >>                                               path9.html
-# seq -s " " -f "]" $Y >>                              path9.html
-# echo "]</p>" >>                                              path9.html
+seq -s " " -f "[" $X >                         path9.text
+echo -n "a" >>                                                 path9.text
+seq -s " " -f "]" $X >>                                path9.text
+
+echo -n "<p>" >                                                path9.html
+seq -s " " -f "[" $X >>                                path9.html
+echo -n "a" >>                                                 path9.html
+seq -s " " -f "]" $Y >>                                path9.html
+echo "]</p>" >>                                                path9.html
 
 
 # Nested block quotes