Skip to content

Escape now protects tags containing non-ASCII characters - #1165

Open
Rohilalala wants to merge 1 commit into
rivo:masterfrom
Rohilalala:fix/escape-non-ascii
Open

Escape now protects tags containing non-ASCII characters#1165
Rohilalala wants to merge 1 commit into
rivo:masterfrom
Rohilalala:fix/escape-non-ascii

Conversation

@Rohilalala

Copy link
Copy Markdown

escapePattern and unescapePattern in util.go accept a tag whose content is ASCII letters, digits or a few punctuation marks. escapedTagPattern in strings.go, which decides what the print functions treat as an escaped tag, accepts anything but brackets.

So text that the print functions unescape can be left untouched by Escape, and printing it then drops a character:

Escape("[中[]")         renders as  [中]           want  [中[]
Escape("[Tom & Bob[]")  renders as  [Tom & Bob]    want  [Tom & Bob[]
Escape("[é[]")          renders as  [é]
Escape("[👍[]")         renders as  [👍]

Both patterns now use the same tag content as escapedTagPattern.

Text that already round-tripped is unaffected. Escape returns a longer string for a tag whose content falls outside the old set — [中] becomes [中[] where it was left alone — but it renders as it did before. Checked over a corpus of 34 tag shapes: 10 escape differently, all of them previously broken or newly protected, and every one renders identically to before.

Not fixed, and unchanged from before: Escape("[[:::x]") renders as [.

The escape and unescape patterns only recognised a tag whose content was
ASCII letters, digits or a few punctuation marks, while escapedTagPattern
in strings.go, which decides what the print functions unescape, accepts
anything but brackets. Text the print functions treated as an escaped tag
was therefore left untouched by Escape, and printing it dropped a
character:

    Escape("[中[]")        rendered as "[中]"
    Escape("[Tom & Bob[]") rendered as "[Tom & Bob]"

Both patterns now use the same tag content as escapedTagPattern. Text that
already round-tripped is unaffected: Escape returns a longer string for a
tag whose content falls outside the old set, but it renders as it did
before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant