fix overzealous `unescape-ext` behavior

pull/127/head
Matthew Butterick 8 years ago
parent 628cb0eaf7
commit 0d1569b36f

@ -78,7 +78,8 @@
(require sugar/coerce) (require sugar/coerce)
(check-equal? (escape-last-ext "foo") (->path "foo")) (check-equal? (escape-last-ext "foo") (->path "foo"))
(check-equal? (escape-last-ext "foo.html") (->path "foo_html")) (check-equal? (escape-last-ext "foo.html") (->path "foo_html"))
(check-equal? (escape-last-ext "foo.html" #\$) (->path "foo$html"))) (check-equal? (escape-last-ext "foo.html" #\$) (->path "foo$html"))
(check-equal? (escape-last-ext "foo_bar.html") (->path "foo_bar_html")))
(define second cadr) (define second cadr)
(define third caddr) (define third caddr)
@ -90,6 +91,10 @@
(->path (->path
(cond (cond
[dir? x] [dir? x]
;; if x has a standard extension, it can't also have an escapable extension, so we're done.
;; saves us the trouble of handling this case in the regexp below,
;; which otherwise would catch things like foo_bar.html (reasoning that _bar.html is all an extension)
[(get-ext x) x]
[else [else
(define x-parts (explode-path x)) (define x-parts (explode-path x))
(define filename (last x-parts)) (define filename (last x-parts))
@ -117,6 +122,8 @@
(check-equal? (unescape-ext "foo_dir/bar_html") (->path "foo_dir/bar.html")) (check-equal? (unescape-ext "foo_dir/bar_html") (->path "foo_dir/bar.html"))
(check-equal? (unescape-ext "foo$html" #\$) (->path "foo.html")) (check-equal? (unescape-ext "foo$html" #\$) (->path "foo.html"))
(check-equal? (unescape-ext "foo_bar__html") (->path "foo_bar_.html")) (check-equal? (unescape-ext "foo_bar__html") (->path "foo_bar_.html"))
(check-equal? (unescape-ext "foo_bar.html") (->path "foo_bar.html"))
(check-equal? (unescape-ext (escape-last-ext "foo_bar.html")) (->path "foo_bar.html"))
(check-equal? (unescape-ext "foo$bar$$html" #\$) (->path "foo$bar$.html"))) (check-equal? (unescape-ext "foo$bar$$html" #\$) (->path "foo$bar$.html")))

@ -1 +1 @@
1468269688 1468998858

Loading…
Cancel
Save