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

Removing 0x00 to clean up B&G 129285. #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

htool
Copy link
Contributor

@htool htool commented Mar 26, 2023

Remove trailing 0x00 bytes from string (which trim doesn't do).

@@ -800,7 +800,7 @@ fieldTypeReaders["String with start/stop byte"] = (pgn, field, bs) => {
var c = bs.readUint8()
buf.writeUInt8(c, idx)
}
return buf.toString('ascii', 0, idx)
return buf.toString('ascii', 0, idx).replace(/\0.*$/g,'')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex is not correct for matching a trailing null.

image

> r = /\0.*$/
/\0.*$/
> s = '\0more'
'\x00more'
> !!s.match(r)
true

Even if it were: are there no legit cases where the last byte would not be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In B&G waypoints the current function includes the \u0000 at the end of the route/waypoint name.
The regex does remove it and works when replaying the pgn.

I noticed trim() functions in other string functions, so this isn't that different.

Probably using an approach like 'ASCII text' is better using a variety of stopbytes, but I didn't want to rewrite the whole function as I don't know how to test many cases.

Copy link
Contributor Author

@htool htool Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the pgn I used to check:

2023-03-26T20:00:05.234Z,7,129285,28,255,8,c1,ff,ff,e0,0b,01,42,41
2023-03-26T20:00:05.253Z,7,129285,28,255,8,c2,52,42,41,44,4f,53,00
2023-03-26T20:00:05.254Z,7,129285,28,255,8,c3,16,00,00,09,01,52,70
2023-03-26T20:00:05.254Z,7,129285,28,255,8,c4,74,30,31,31,00,d9,d5
2023-03-26T20:00:05.255Z,7,129285,28,255,8,c5,12,05,2e,c9,75,df,01
2023-03-26T20:00:05.256Z,7,129285,28,255,8,c6,00,09,01,52,70,74,30
2023-03-26T20:00:05.257Z,7,129285,28,255,8,c7,31,33,00,55,96,c0,07
2023-03-26T20:00:05.257Z,7,129285,28,255,8,c8,e8,98,74,dc,ff,ff,ff

@sbender9
Copy link
Member

Is this still an issue? I would love to fix it, but not loving this solution...

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