Skip to content

Commit f96082a

Browse files
committed
parse: Fix bug in handling of link destinations
This was a very silly bug: a missing ^ at the start of a regular expression that almost always failed to match despite scanning the entire input most of the time, when it was called. The result was some very strange behavior when it did happen to match. fixes #4
1 parent 843f42b commit f96082a

File tree

2 files changed

+54
-1
lines changed
  • commonmark-lib/commonmark/private/parse
  • commonmark-test/tests/commonmark/parse

2 files changed

+54
-1
lines changed

commonmark-lib/commonmark/private/parse/common.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122

123123
;; <https://spec.commonmark.org/0.30/#link-destination>
124124
(define (try-peek-link-destination in [start-pos 0])
125-
(match (regexp-match-peek #px"<([^\r\n]*?)(?<!\\\\)>" in start-pos)
125+
(match (regexp-match-peek #px"^<([^\r\n]*?)(?<!\\\\)>" in start-pos)
126126
; First, the simple case: a destination enclosed in <angle brackets>.
127127
[(list peeked-bytes dest-bytes)
128128
(list (+ start-pos (bytes-length peeked-bytes))
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#lang racket/base
2+
3+
;; Regression test for <https://github.com/lexi-lambda/racket-commonmark/issues/4>.
4+
5+
(require commonmark/struct
6+
rackunit
7+
"../test-util.rkt")
8+
9+
(check-equal? (md "[a link](http://example.com).</span>")
10+
(document
11+
(list
12+
(paragraph
13+
(list (link "a link" "http://example.com" #f) "." (html "</span>"))))
14+
'()))
15+
16+
(check-equal? (md "[a link][1].</span>"
17+
""
18+
"[1]: http://example.com")
19+
(document
20+
(list
21+
(paragraph
22+
(list (link "a link" "http://example.com" #f) "." (html "</span>"))))
23+
'()))
24+
25+
(check-equal? (md "This <span>is _emphasis_ and [a link](http://example.com).</span>")
26+
(document
27+
(list
28+
(paragraph
29+
(list "This " (html "<span>") "is " (italic "emphasis") " and " (link "a link" "http://example.com" #f) "." (html "</span>"))))
30+
'()))
31+
32+
(check-equal? (md "This <span>is _emphasis_ and [a link][1].</span>"
33+
""
34+
"[1]: http://example.com")
35+
(document
36+
(list
37+
(paragraph
38+
(list "This " (html "<span>") "is " (italic "emphasis") " and " (link "a link" "http://example.com" #f) "." (html "</span>"))))
39+
'()))
40+
41+
(check-equal? (md "This <span>is _emphasis_ and [a link](http://example.com).")
42+
(document
43+
(list
44+
(paragraph
45+
(list "This " (html "<span>") "is " (italic "emphasis") " and " (link "a link" "http://example.com" #f) ".")))
46+
'()))
47+
48+
(check-equal? (md "This <span>is _emphasis_ and [a link](http://example.com).</div>")
49+
(document
50+
(list
51+
(paragraph
52+
(list "This " (html "<span>") "is " (italic "emphasis") " and " (link "a link" "http://example.com" #f) "." (html "</div>"))))
53+
'()))

0 commit comments

Comments
 (0)