Skip to content

Commit

Permalink
Improve the regex and add tests to prove it works (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwats authored Oct 13, 2020
1 parent 400ec52 commit 2d861a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion dap-launch.el
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ supported."
(or (: "//" (* nonl) eol)
(: "/*" (* (or (not (any ?*))
(: (+ ?*) (not (any ?/))))) (+ ?*) ?/)
(: "," (group (* (any blank ?\C-j)) (any ?\} ?\])))))
(: "," (group (* (any blank space ?\v ?\u2028 ?\u2029))
(any ?\} ?\])))))
(: "\"" (* (or (not (any ?\\ ?\")) (: ?\\ nonl))) "\"")))
nil t)
;; we matched a comment
Expand Down
24 changes: 19 additions & 5 deletions test/dap-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,26 @@

(ert-deftest dap-launch-test--delete-commas ()
(let* ((orig "{
\"abc\": 123,
\"conf\": [
{
\"a\": \"b\",\t\v\u00A0
},
{
\"b\": \"c\",\xD\u2028\u2029
},\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006
],\u2007\u2008\u2009\u200A\u202F\u205F\u3000
}")
(post-exp (dap-launch-test--sanitize-json orig)))
(should (string= post-exp "{
\"abc\": 123
}"))))
(expected "{
\"conf\": [
{
\"a\": \"b\"\t\v\u00A0
},
{
\"b\": \"c\"\xD\u2028\u2029
}\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006
]\u2007\u2008\u2009\u200A\u202F\u205F\u3000
}"))
(should (string= (dap-launch-test--sanitize-json orig) expected))))

(ert-deftest dap-launch-test--comment-in-string ()
(let ((orig "\"// orig\""))
Expand Down

0 comments on commit 2d861a3

Please sign in to comment.