mirror of
https://github.com/Orc/discount.git
synced 2026-09-25 04:10:00 +03:00
Update some tests, add some more tests from Mike Schiraldi,
redo puturl and the url grabbers to do debackslashification in puturl
This commit is contained in:
+26
-11
@@ -323,7 +323,7 @@ ___mkd_reparse(char *bfr, int size, int flags, MMIOT *f)
|
||||
* write out a url, escaping problematic characters
|
||||
*/
|
||||
static void
|
||||
puturl(char *s, int size, MMIOT *f)
|
||||
puturl(char *s, int size, MMIOT *f, int display)
|
||||
{
|
||||
unsigned char c;
|
||||
|
||||
@@ -334,7 +334,13 @@ puturl(char *s, int size, MMIOT *f)
|
||||
Qstring("&", f);
|
||||
else if ( c == '<' )
|
||||
Qstring("<", f);
|
||||
else if ( isalnum(c) || ispunct(c) )
|
||||
else if ( c == '\\' ) {
|
||||
if ( size && (ispunct(*s)||isspace(*s)) )
|
||||
/* silently discard the backslash */ ;
|
||||
else
|
||||
Qchar(c, f);
|
||||
}
|
||||
else if ( isalnum(c) || ispunct(c) || (display && isspace(c)) )
|
||||
Qchar(c, f);
|
||||
else
|
||||
Qprintf(f, "%%%02X", c);
|
||||
@@ -463,7 +469,7 @@ linkysize(MMIOT *f, Footnote *ref)
|
||||
static int
|
||||
linkyurl(MMIOT *f, int image, Footnote *p)
|
||||
{
|
||||
int c;
|
||||
int c, size;
|
||||
int mayneedtotrim=0;
|
||||
|
||||
if ( (c = eatspace(f)) == EOF )
|
||||
@@ -474,16 +480,19 @@ linkyurl(MMIOT *f, int image, Footnote *p)
|
||||
mayneedtotrim=1;
|
||||
}
|
||||
|
||||
while ( (c = peek(f,1)) != ')' ) {
|
||||
T(p->link) = cursor(f);
|
||||
for ( S(p->link)=0; (c = peek(f,1)) != ')'; ++S(p->link) ) {
|
||||
if ( c == EOF )
|
||||
return 0;
|
||||
else if ( (c == '"' || c == '\'') && linkytitle(f, c, p) )
|
||||
break;
|
||||
else if ( image && (c == '=') && linkysize(f, p) )
|
||||
break;
|
||||
else if ( (c == '\\') && ispunct(peek(f,2)) )
|
||||
else if ( (c == '\\') && ispunct(peek(f,2)) ) {
|
||||
++S(p->link);
|
||||
pull(f);
|
||||
EXPAND(p->link) = pull(f);
|
||||
}
|
||||
pull(f);
|
||||
}
|
||||
if ( peek(f, 1) == ')' )
|
||||
pull(f);
|
||||
@@ -609,8 +618,8 @@ linkyformat(MMIOT *f, Cstring text, int image, Footnote *ref)
|
||||
|
||||
if ( tag->kind & IS_URL ) {
|
||||
if ( f->base && T(ref->link) && (T(ref->link)[tag->szpat] == '/') )
|
||||
puturl(f->base, strlen(f->base), f);
|
||||
puturl(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, f);
|
||||
puturl(f->base, strlen(f->base), f, 0);
|
||||
puturl(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, f, 0);
|
||||
}
|
||||
else
|
||||
___mkd_reparse(T(ref->link) + tag->szpat, S(ref->link) - tag->szpat, INSIDE_TAG, f);
|
||||
@@ -811,9 +820,9 @@ process_possible_link(MMIOT *f, int size)
|
||||
}
|
||||
else if ( isautoprefix(text) ) {
|
||||
Qstring("<a href=\"", f);
|
||||
puturl(text,size,f);
|
||||
puturl(text,size,f, 0);
|
||||
Qstring("\">", f);
|
||||
puturl(text,size,f);
|
||||
puturl(text,size,f, 1);
|
||||
Qstring("</a>", f);
|
||||
return 1;
|
||||
}
|
||||
@@ -839,6 +848,10 @@ maybe_tag_or_link(MMIOT *f)
|
||||
for ( size=0; (c = peek(f, size+1)) != '>'; size++) {
|
||||
if ( c == EOF )
|
||||
return 0;
|
||||
else if ( c == '\\' ) {
|
||||
maybetag=0;
|
||||
size++;
|
||||
}
|
||||
else if ( isspace(c) )
|
||||
break;
|
||||
else if ( ! (c == '/' || isalnum(c) ) )
|
||||
@@ -875,7 +888,9 @@ maybe_autolink(MMIOT *f)
|
||||
/* greedily scan forward for the end of a legitimate link.
|
||||
*/
|
||||
for ( size=0; (c=peek(f, size+1)) != EOF; size++ )
|
||||
if ( !(isalnum(c) || strchr("/:._%~@", c)) )
|
||||
if ( c == '\\' )
|
||||
++size;
|
||||
else if ( !(isalnum(c) || strchr("/:._%~@&?=", c) || (c & 0x80)) )
|
||||
break;
|
||||
|
||||
if ( (size > 1) && process_possible_link(f, size) ) {
|
||||
|
||||
+4
-3
@@ -9,17 +9,18 @@ try() {
|
||||
./echo -n " $S "
|
||||
|
||||
Q=`./echo "$2" | ./markdown`
|
||||
count=`./echo "$Q" | grep "$3" | wc -l`
|
||||
|
||||
if [ $count -eq 1 ]; then
|
||||
if [ "$3" = "$Q" ]; then
|
||||
./echo "ok"
|
||||
else
|
||||
./echo "FAILED"
|
||||
./echo "wanted: $3"
|
||||
./echo "got: $Q"
|
||||
rc=1
|
||||
fi
|
||||
}
|
||||
|
||||
try 'backslashes in []()' '[foo](http://\this\is\.a\test\(here\))' \
|
||||
'<p><a href="http://\\this\\is\.a\\test(here)">foo</a></p>'
|
||||
'<p><a href="http://\this\is.a\test(here)">foo</a></p>'
|
||||
|
||||
exit $rc
|
||||
|
||||
@@ -53,4 +53,20 @@ try -fnopants '[]() with a single quote mark' \
|
||||
'[Poe'"'"'s law](http://rationalwiki.com/wiki/Poe'"'"'s_Law)' \
|
||||
'<p><a href="http://rationalwiki.com/wiki/Poe'"'"'s_Law">Poe'"'"'s law</a></p>'
|
||||
|
||||
try -fautolink 'autolink url with escaped spaces' \
|
||||
'http://\(here\ I\ am\)' \
|
||||
'<p><a href="http://(here%20I%20am)">http://(here I am)</a></p>'
|
||||
|
||||
try -fautolink 'autolink café_racer' \
|
||||
'http://en.wikipedia.org/wiki/café_racer' \
|
||||
'<p><a href="http://en.wikipedia.org/wiki/caf%C3%A9_racer">http://en.wikipedia.org/wiki/caf%C3%A9_racer</a></p>'
|
||||
|
||||
try -fautolink 'autolink url with arguments' \
|
||||
'http://foo.bar?a&b=c' \
|
||||
'<p><a href="http://foo.bar?a&b=c">http://foo.bar?a&b=c</a></p>'
|
||||
|
||||
try -fautolink 'autolink url with escaped ()' \
|
||||
'http://a.com/\(foo\)' \
|
||||
'<p><a href="http://a.com/(foo)">http://a.com/(foo)</a></p>'
|
||||
|
||||
exit $rc
|
||||
|
||||
Reference in New Issue
Block a user