From 43428e759d9fbc5a319c2b929bfb4469938cc386 Mon Sep 17 00:00:00 2001 From: clsr Date: Thu, 23 Dec 2021 01:54:47 +0000 Subject: Add EscapeAll and escape all spaces in links --- cnmfmt/cnmfmt.go | 2 +- cnmfmt/cnmfmt_test.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'cnmfmt') diff --git a/cnmfmt/cnmfmt.go b/cnmfmt/cnmfmt.go index 1e5b6ee..3e38978 100644 --- a/cnmfmt/cnmfmt.go +++ b/cnmfmt/cnmfmt.go @@ -195,7 +195,7 @@ func (t Text) WriteIndent(w io.Writer, n int) error { if span.Text != "" { pad = " " } - line = append(line, "@@", cnm.Escape(span.Format.Link), pad) + line = append(line, "@@", cnm.EscapeAll(span.Format.Link), pad) } } } diff --git a/cnmfmt/cnmfmt_test.go b/cnmfmt/cnmfmt_test.go index 5d50b18..2ad92cb 100644 --- a/cnmfmt/cnmfmt_test.go +++ b/cnmfmt/cnmfmt_test.go @@ -127,6 +127,9 @@ var parseTests = map[string]Text{ "@@foo ": Text{[]Span{ Span{Format{Link: "foo"}, ""}, }}, + "@@foo\\ bar baz quux@@": Text{[]Span{ + Span{Format{Link: "foo bar"}, "baz quux"}, + }}, "@@foo\\": Text{[]Span{ Span{Format{Link: "foo\\"}, ""}, }}, @@ -213,9 +216,9 @@ func textEqual(a, b Text) bool { } var escapeTests = map[string]string{ - "\n\r\t\v\x00": "\\n\\r\\t\v\\x00", + "\n\r\t\v\x00": "\\n\\r\\t\v\\x00", "@@!!##\"\"//\"\"__``**%%^^&&++==\x01\x01\\": "\\@\\@!!##\\\"\\\"//\\\"\\\"\\_\\_\\`\\`\\*\\*%%^^&&++==\x01\x01\\\\", - `foo\@\@bar`: `foo\\\@\\\@bar`, + `foo\@\@bar`: `foo\\\@\\\@bar`, } func TestEscape(t *testing.T) { @@ -269,6 +272,10 @@ var parseTextTests = map[string]TextFmtContents{ Text{[]Span{Span{Format{Emphasized: true}, "foo"}}}, Text{[]Span{Span{Format{}, "bar"}}}, }}, + + "@@foo\\ bar baz quux@@": TextFmtContents{[]Text{ + Text{[]Span{Span{Format{Link: "foo bar"}, "baz quux"}}}, + }}, } func TestParseTextFmt(t *testing.T) { @@ -335,6 +342,10 @@ var writeTests = map[string]TextFmtContents{ }}, }}, + "@@foo\\ bar baz quux\n": TextFmtContents{[]Text{ + Text{[]Span{Span{Format{Link: "foo bar"}, "baz quux"}}}, + }}, + "foo**bar``baz**quux\n\n" + "\\ \"\"qwe\\ \"\"__\\ asd \\ __``zxc``**\\ \n\n" + "__@@http://example.com/__/ exa__mple@@ @@href text@@__ test\n": TextFmtContents{[]Text{ -- cgit