From: Paul Hänsch Date: Wed, 9 Oct 2024 05:10:39 +0000 (+0200) Subject: bugfix: avoid endless loops for some incomplete matches X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=cgilite bugfix: avoid endless loops for some incomplete matches --- diff --git a/markdown.awk b/markdown.awk index 356a987..bef97d1 100755 --- a/markdown.awk +++ b/markdown.awk @@ -372,11 +372,10 @@ function inline( line, LOCAL, len, text, code, href, guard, ret ) { ret = ret HTML(substr(line, 1, 1)); line = substr(line, 2); continue; - # continue walk over string - } else { - ret = ret substr(line, 1, 1); line = substr(line, 2); - continue; - } + } # inline patterns end + + # continue walk over string + ret = ret substr(line, 1, 1); line = substr(line, 2); } return ret; } @@ -851,10 +850,10 @@ function _block( block, LOCAL, st, len, text, title, attrib, href, guard, code, ret = ret _block(substr(block, 1, st - 1)) "
\n"; block = substr(block, st + len); continue; + } # block patterns end + # Plain paragraph - } else { - return ret "

" inline(block) "

\n"; - } + return ret "

" inline(block) "

\n"; } return ret; } diff --git a/tests-markdown.sh b/tests-markdown.sh index a834391..6df4224 100755 --- a/tests-markdown.sh +++ b/tests-markdown.sh @@ -1,6 +1,6 @@ #!/bin/sh -runtimes="gawk bawk mawk goawk" +runtimes="gawk busybox mawk goawk" BR=' ' @@ -9,7 +9,7 @@ fail() { printf '%s\n' "$@"; exit 1; } awk() { /bin/awk "$@"; } md_gawk() { gawk -f markdown.awk "$@"; } -md_bawk() { busybox awk -f markdown.awk "$@"; } +md_busybox() { busybox awk -f markdown.awk "$@"; } md_mawk() { mawk -f markdown.awk "$@"; } md_goawk() { goawk -f markdown.awk "$@"; } @@ -45,6 +45,7 @@ assert '~sub~' '

sub

' "subscript" assert "foo ${BR}bar" "

foo
${BR}bar

" 'double space line break' assert '```©```' "

©

" "code span escape" +assert '````' "
````
" "empty code span" assert '_emphasized text_' '

emphasized text

' "em" assert '_emphasized_text_' '

emphasized_text

' "em" @@ -190,6 +191,14 @@ not be but &shy; <escaped>' \ "fenced code block" +assert 'foobar +```` +foobar' \ +'

foobar +```` +foobar

' \ +"Open Fence" + # Block Images assert '![Testbild](Test Bild.jpg)' \ '
Testbild
' \