[go: up one dir, main page]

Skip to content
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

Merged
merged 2 commits into from
Mar 31, 2022
Merged

Unescape hex/unicode for sample serial data #949

merged 2 commits into from
Mar 31, 2022

Conversation

akberenz
Copy link
Member

For #877

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)));
Copy link
Member

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

Copy link
Member

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))
            })
        );

Copy link
Member Author
@akberenz akberenz Mar 30, 2022

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

@klabarge
Copy link
Member

What data should I be testing?

I'm kind of arbitrarily sending stuff so not sure if it's valid.

Test 1

send: hi, serial port\n
logs:"data":"hi, serial port\n"

Test 2

send: hi, serial port\u
logs:"data":"hi, serial port\\u"
error: java.lang.IllegalArgumentException: Less than 4 hex digits in unicode value: '\u' due to end of CharSequence

@tresf
Copy link
Contributor
tresf commented Mar 31, 2022

What data should I be testing?

I'm kind of arbitrarily sending stuff so not sure if it's valid.

Test 1

send: hi, serial port\n logs:"data":"hi, serial port\n"

Test 2

send: hi, serial port\u logs:"data":"hi, serial port\\u" error: java.lang.IllegalArgumentException: Less than 4 hex digits in unicode value: '\u' due to end of CharSequence

Those are pretty good tests. Some known hex would be nice (newline, tab, a-z stuff, but in hex format).

@klabarge
Copy link
Member

I sent hex with new lines and tabs and it seems ok.

68 69 0A 09 73 65 72 69 61 6C 0A 70 6F 72 74

@tresf
Copy link
Contributor
tresf commented Mar 31, 2022
thanks
	kyle
merging

@tresf tresf merged commit 25f7576 into master Mar 31, 2022
@tresf tresf deleted the hex-unescape branch August 5, 2022 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants