Skip to content

Double escaping? #14

@exside

Description

@exside

Not sure if this makes sense when having the escape spec in mind (you know that way better!), but what if a character is already escaped within the string to escape? The current code will double escape escaped stuff, I'm using a custom version that doesn't do that, e.g. changed to this:

// If the character is not handled by one of the above rules and is
// greater than or equal to U+0080, is `-` (U+002D) or `\` (U+005C) or 
// `_` (U+005F), or is preceded by a `\` (escape) already,
// or is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
// U+005A), or [a-z] (U+0061 to U+007A), […]
if (
	codeUnit >= 0x0080 ||
	codeUnit == 0x002D ||
	codeUnit == 0x005C || // custom: no double escapes!
	codeUnit == 0x005F ||
	string.charCodeAt(index-1) == 0x005C || // custom: no double escapes!
	codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
	codeUnit >= 0x0041 && codeUnit <= 0x005A ||
	codeUnit >= 0x0061 && codeUnit <= 0x007A
) {
	// the character itself
	result += string.charAt(index);
	continue;
}

if this makes any sense for this project I'm glad to open a PR with the change, but I can imagine it is either against the spec, the purpose of this module or will break backward compatibility and can therefore not be done...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions