-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unescape hex/unicode for sample serial data #949
Conversation
sample.html
Outdated
serialData.data = serialData.data.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t"); | ||
//allow some escape characters (newlines, tabs, hex/unicode) | ||
serialData.data = serialData.data.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t") | ||
.replace(/\\[xu]([\dA-Fa-f]+)/g, (m, s1) => String.fromCharCode(parseInt(s1, 16))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This arrow function breaks IE11 support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be rewritten like so?
serialData.data = serialData.data.replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\t/g, "\t")
.replace(/\\[xu]([\dA-Fa-f]+)/g, (m, s1).then(function() {
String.fromCharCode(parseInt(s1, 16))
})
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but i found a case in retesting where the \x codes can try to collect too many values to convert because of the \u regex combo, so I pushed up a change where the function is a variable to be used for both now split
What data should I be testing? I'm kind of arbitrarily sending stuff so not sure if it's valid. Test 1send: Test 2send: |
Those are pretty good tests. Some known hex would be nice (newline, tab, a-z stuff, but in hex format). |
I sent hex with new lines and tabs and it seems ok.
|
|
For #877