Closed serious-sammy closed 1 year ago
Replacing with the following seems to help:
.trim()
// Replace one or more consecutive whitespace characters (spaces, tabs,
// or line breaks) with a single space.
.replace(/\s+/g, ' ')
// Now encode numbers to little endian hex. Note that numbers are not
// enclosed in <>, since <> represents hex code already encoded.
// The regex below will match one or more digits within a string,
// except if the sequence is surrounded by "<" and ">"
.replace(/(<\d+>)|\b\d+\b/g, (match) =>
match.startsWith('<') ? match : numberEncodeAsm(Number(match))
)
// we don't have numbers anymore, now it's safe to remove < and > since we
// know that every remaining is either an op_code or a hex encoded number
.replace(/[<>]/g, '');
Thanks @serious-sammy . This looks good to me. Do you want to submit a PR with the proposal? I can do it for you if you don't want to (or have the time). Let me know.
I'd appreciate if you would do it 🙏
Thanks for the report @serious-sammy . I've updated npm with a new version with the change.
Currently, lookbehind regex assertions are not supported in Safari and therefore iOS (all iOS browsers are just reskinned Safari). Because of this, the library can't be used on Safari or iOS, because when imported, the following exception is thrown:
SyntaxError: Invalid regular expression: invalid group specifier name
. The root cause seems to be this line, which uses a lookbehind?<
.