You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Check for non-ASCII entries in wpt, list files #41
The site update program should report and error and continue if a user's list file or a wpt file as non-ASCII characters. Currently, the site update program crashes without an especially helpful error. This might be best done as a pre-processing step or as the first task in a site update that will be noticed quickly rather than several minutes into the site update process.
Thinking this thru, just in terms of WPT files for the moment...
A non-ASCII character on any given line would have to wind up in the primary label, alternate labels, or URL.
The URL doesn't get stored, and shouldn't matter as long as we can extract the lat_string and lng_string from its parts, and parse them. The proposed MALFORMED_URL datacheck should catch & report all of these, and allow siteupdate to continue without crashing.
For primary labels, we similarly have the LABEL_INVALID_CHAR datacheck.
This leaves us with just AltLabels. Are there even any known AltLabels with non-ASCII characters currently? If so, should they be left in for compatibility's sake? If not, should we prohibit them & make sure none creep in in the future?
The OP in this issue predates the addition of PYTHONIOENCODING='utf-8' by about 10 months. With that now in place, is this even as much of in issue anymore?
This leaves us with just AltLabels. Are there even any known AltLabels with non-ASCII characters currently?
I don't think so. They had likely made trouble in the past.
If so, should they be left in for compatibility's sake? If not, should we prohibit them & make sure none creep in in the future?
I think that non-ASCII character are usually not added on purpose but by accident. And by accident, characters can appear everywhere in any file. If you check the file, you need to check the whole file.
Non-ASCII characters used to cause problems in site updates on FreeBSD before the utf-8 setting allowed that. Notorious for this would be commented-out lines in systems.csv, where international characters are permitted.
I think that non-ASCII character are usually not added on purpose but by accident.
This is true.
And by accident, characters can appear everywhere in any file.
*sigh*, also true.
Sometimes I'll be editing some C++, and it won't compile (after pasting?), due to non-ASCII characters I can't see in pluma. I delete the offending line, retype it, and then compilesville, daddy-o.
If you check the file, you need to check the whole file.
I'd say, only the necessary parts, just what would affect the functionality of the site.
URLs aren't stored; we just need to extract lat_string & lng_string and convert them to float. To that end, http://madmagazine.com/?[%15]=43.661855&[%FF]=-70.270169 is a valid URL, that can be parsed.
Primary labels are already checked.
This leaves us AltLabels.
I've tested out a version of siteupdate that expands the LABEL_INVALID_CHAR datacheck to AltLabels. On noreaster, it didn't add a noticeable amount of runtime, in one case even performing the data checks faster than the reference, siteupdate.py in #158.
Who knows what other processes noreaster may have been running at the same time though; I'll see if I get more deterministic results on BiggaTomato.
On noreaster, it didn't add a noticeable amount of runtime, in one case even performing the data checks faster than the reference, siteupdate.py in #158.
Who knows what other processes noreaster may have been running at the same time though; I'll see if I get more deterministic results on BiggaTomato.
On BiggaTomato:
0.2 s slower, best-case
0.4 s slower, average
0.5 s slower, worst-case
Not much harm in expanding LABEL_INVALID_CHAR to AltLabels, just to be safe.
What would be the more useful syntax for reporting them? me.us001;NH/ME;;;LABEL_INVALID_CHAR;+Foo#Bar, or me.us001;+Foo#Bar;;;LABEL_INVALID_CHAR;?
Right now, for primary labels only, the Info field is not used, E.G. chngd.g94;?;;;LABEL_INVALID_CHAR;
yakra@BiggaTomato:~/proj/tmtools/siteupdate$ diff /home/yakra/tm2/DataProcessing/siteupdate/python-teresco/logs/users/lowenbrau.log /home/yakra/proj/tmtools/siteupdate/logs/users/lowenbrau.log | tee lowenbrau.diff
1c1< Log file created at: 2019-01-11 02:56:19.536042---> Log file created at: Fri Jan 11 03:44:42 201952,53c52< Waypoint label(s) not found in line: ON ON405 ON/USA PorRd< Processed 1686 good lines marking 21054 segments traveled.---> Processed 1687 good lines marking 21056 segments traveled.55,56c54,55< Overall in active systems: 30414.33 of 881553.84 mi (3.5%)< Overall in active+preview systems: 30414.51 of 1203407.92 mi (2.5%)---> Overall in active systems: 30414.83 of 881553.84 mi (3.5%)> Overall in active+preview systems: 30415.01 of 1203407.92 mi (2.5%)91a91> ON: 0.50 of 7509.95 mi (0.0%), 0.50 of 7509.95 mi (0.0%)124c124,128< System canonf (active) overall: 0.00 of 1244.18 mi (0.0%)---> System canonf (active) overall: 0.50 of 1244.18 mi (0.0%)> System canonf by route (traveled routes only):> ON405: 0.50 of 5.93 mi (8.5%)> (ON ON405 only)> System canonf connected routes traveled: 1 of 19 (5.3%), clinched: 0 of 19 (0.0%).3875c3879< Traveled 47 of 225 (20.9%), Clinched 0 of 225 (0.0%) active systems---> Traveled 48 of 225 (21.3%), Clinched 0 of 225 (0.0%) active systems
#176 fixes the problem with the trailing null zeros preventing lowenbrau from being credited for ON405.
Other than that, now that we have the PYTHONIOENCODING='utf-8' setting, as noted, non-ASCII characters aren't really a showstopper anymore.
Any non-ASCII character in a .list file would be either:
in a comment, and thus ignored,
in a line with <> 4 non-comment fields, and thus ignored,
in the region or route fields, thus producing a normal Unknown region/highway combo in line: log error, or
one of the waypoint labels, thus producing a normal Waypoint label(s) not found in line: log error.
I don't see much reason to keep this issue open anymore... anyone else?
Now, I'm thinking all this .list line checking is overkill.
This can all result in control / non-ASCII characters in log files, which can prevent some text editors from reading them.
Do we care about this? Chances are, if it's a UTF-8 byte order mark or any international characters a traveler could type into their .list, any modern web browser will display the resulting .log line just fine, as should the same text editor the traveler used to create their .list.
Listing the actual original offending line in an error report in a log, rather than overwriting all non-ascii chars with a ? will be nicer looking, and probably more immediately useful to the user.
.wpt files have been addressed for some time now.
with the PYTHONIOENCODING='utf-8' setting, .lists should be fine now too, with the existing error checks (the ones that go into user logs) sufficient to flag anything we truly want to check for.
Any objections if I decide non-ascii characters are OK in .list files, revert those C++ changes, and close this issue?
Chances are, if it's a UTF-8 byte order mark or any international characters a traveler could type into their .list, any modern web browser will display the resulting .log line just fine, as should the same text editor the traveler used to create their .list.
Those will only display right if at the beginning of a line. When displayed mid-line in an Incorrect format line: , we see, well, that. Fixing #215 should make this a non-issue.
I agree a .log with the actual offending text will be more useful to a user.
Definitely the case for Incorrect format lines. Theoretically, the user can see that the number of fields in the line is wrong, and will know what to fix. Or maybe the line is just intended as a comment, without using #.
philimon.log:
3,6c3,6< Incorrect format line: ======ΑΛΒΑΝΙΑ======< Incorrect format line: ======ΑΝΔΟΡΡΑ======< Incorrect format line: ======ΑΥΣΤΡΙΑ======< Incorrect format line: ======ΒΕΛΓΙΟ======---> Incorrect format line: ======??????????????====== [line contains invalid character(s)]> Incorrect format line: ======??????????????====== [line contains invalid character(s)]> Incorrect format line: ======??????????????====== [line contains invalid character(s)]> Incorrect format line: ======????????????====== [line contains invalid character(s)]
This junk isn't very helpful.
OTOH:
chaddean.log:
2c2< Waypoint label(s) not found in line: FL FL44 FL19�/98 US441---> Waypoint label(s) not found in line: FL FL44 FL19?/98 US441 [line contains invalid character(s)]
This looks a little nefarious. That's 0x1F, the ascii field separator. No idea how it got in there, but...
Firefox & Chromium won't treat this as a regular text file; I'm prompted to download it & either open or save.
When chaddean opens it up in a text editor, it's possible he won't see any indication of the stray character at all. It may just be blank. He could see the error line and say, "What the heck? Looks like a perfectly fine waypoint label to me."
So, there could be some use for taking this approach when a control character is part of a region, route or label field.
These errors are rare; these are the only 2 user log files containing non-ascii characters. I'll fix the Incorrect format line cases, and go no-build on the others for now while giving a bit more thought to how to handle them.
Heh -- lowenbrau.list somehow has a bunch of extra null \0s at the end of a file. If a null \0 ever makes its way into the middle of a file, all hell will break loose. I hope that never happens.
chaddean.log:
2c2< Waypoint label(s) not found in line: FL FL44 FL19�/98 US441---> Waypoint label(s) not found in line: FL FL44 FL19?/98 US441 [line contains invalid character(s)]
It makes sense to replace characters and add a note when control characters (< 0x20) are included.
Heh -- lowenbrau.list somehow has a bunch of extra null \0s at the end of a file. If a null \0 ever makes its way into the middle of a file, all hell will break loose. I hope that never happens.
Going full bore with mitigating any null \0s is overkill when as it stands this is essentially a fix for an oddity in a single file -- multiple or much more complicated strips, and then treating them as a delimiter ...
On the C++ side, we're not using strtok to separate lines anymore, so a potential rewrite would be simpler. But still.
Similar to removing the BOM from the first line only, we can rstrip('\x00') from the last line only, and save some processing time on the rest.
Activity
yakra commentedon Nov 20, 2018
https://github.com/TravelMapping/UserData/blob/9ab420d7cc23d79b6d24f224c7186c88ee6ef777/list_files/lowenbrau.list
yakra commentedon Dec 21, 2018
Thinking this thru, just in terms of WPT files for the moment...
A non-ASCII character on any given line would have to wind up in the primary label, alternate labels, or URL.
lat_stringandlng_stringfrom its parts, and parse them. The proposed MALFORMED_URL datacheck should catch & report all of these, and allow siteupdate to continue without crashing.PYTHONIOENCODING='utf-8'by about 10 months. With that now in place, is this even as much of in issue anymore?michihdeu commentedon Dec 21, 2018
I don't think so. They had likely made trouble in the past.
I think that non-ASCII character are usually not added on purpose but by accident. And by accident, characters can appear everywhere in any file. If you check the file, you need to check the whole file.
jteresco commentedon Dec 21, 2018
Non-ASCII characters used to cause problems in site updates on FreeBSD before the utf-8 setting allowed that. Notorious for this would be commented-out lines in systems.csv, where international characters are permitted.
yakra commentedon Dec 30, 2018
@yakra wrote:
Confirmed, there are none.
@michihdeu wrote:
This is true.
*sigh*, also true.
Sometimes I'll be editing some C++, and it won't compile (after pasting?), due to non-ASCII characters I can't see in pluma. I delete the offending line, retype it, and then compilesville, daddy-o.
@jteresco wrote:
Now that we use this option, non-ASCII characters are much less of a showstopper.
@michihdeu wrote:
I'd say, only the necessary parts, just what would affect the functionality of the site.
URLs aren't stored; we just need to extract
lat_string&lng_stringand convert them to float. To that end, http://madmagazine.com/?[%15]=43.661855&[%FF]=-70.270169 is a valid URL, that can be parsed.Primary labels are already checked.
This leaves us AltLabels.
I've tested out a version of siteupdate that expands the LABEL_INVALID_CHAR datacheck to AltLabels. On noreaster, it didn't add a noticeable amount of runtime, in one case even performing the data checks faster than the reference, siteupdate.py in #158.
Who knows what other processes noreaster may have been running at the same time though; I'll see if I get more deterministic results on BiggaTomato.
michihdeu commentedon Dec 30, 2018
I didn't know that. I understand now why my previous post was... kind of useless 😃
yakra commentedon Dec 30, 2018
On BiggaTomato:
0.2 s slower, best-case
0.4 s slower, average
0.5 s slower, worst-case
Not much harm in expanding LABEL_INVALID_CHAR to AltLabels, just to be safe.
What would be the more useful syntax for reporting them?
me.us001;NH/ME;;;LABEL_INVALID_CHAR;+Foo#Bar, orme.us001;+Foo#Bar;;;LABEL_INVALID_CHAR;?Right now, for primary labels only, the
Infofield is not used, E.G.chngd.g94;?;;;LABEL_INVALID_CHAR;yakra commentedon Jan 2, 2019
Re .list files:
The final line,
ON ON405 ON/USA PorRd, is followed by 1486 null\0s, before a final CRLF.We can see that this line is not parsed:
http://travelmapping.net/logs/users/lowenbrau.log
http://travelmapping.net/hb/index.php?units=miles&u=lowenbrau&r=on.on405
yakra commentedon Jan 11, 2019
yakra@BiggaTomato:~/proj/tmtools/siteupdate$ diff /home/yakra/tm2/DataProcessing/siteupdate/python-teresco/logs/users/lowenbrau.log /home/yakra/proj/tmtools/siteupdate/logs/users/lowenbrau.log | tee lowenbrau.diff
yakra commentedon Jan 22, 2019
#176 fixes the problem with the trailing null zeros preventing lowenbrau from being credited for ON405.
Other than that, now that we have the
PYTHONIOENCODING='utf-8'setting, as noted, non-ASCII characters aren't really a showstopper anymore.Any non-ASCII character in a .list file would be either:
Unknown region/highway combo in line:log error, orWaypoint label(s) not found in line:log error.I don't see much reason to keep this issue open anymore... anyone else?
yakra commentedon Mar 12, 2019
This would trigger the
Incorrect format line:error, and output the offending line to the .logThis can all result in control / non-ASCII characters in log files, which can prevent some text editors from reading them.
Check for non-ASCII entries in list files
yakra commentedon Mar 12, 2019
C++: yakra@0e8298e
yakra commentedon Apr 14, 2020
Per #41 (comment), I made some changes to the C++ version pretty early on.
Now, I'm thinking all this .list line checking is overkill.
Do we care about this? Chances are, if it's a UTF-8 byte order mark or any international characters a traveler could type into their .list, any modern web browser will display the resulting .log line just fine, as should the same text editor the traveler used to create their .list.
Listing the actual original offending line in an error report in a log, rather than overwriting all non-ascii chars with a
?will be nicer looking, and probably more immediately useful to the user.PYTHONIOENCODING='utf-8'setting, .lists should be fine now too, with the existing error checks (the ones that go into user logs) sufficient to flag anything we truly want to check for.Any objections if I decide non-ascii characters are OK in .list files, revert those C++ changes, and close this issue?
jteresco commentedon Apr 14, 2020
I agree a .log with the actual offending text will be more useful to a user. I am fine with what you propose.
yakra commentedon Apr 14, 2020
Those will only display right if at the beginning of a line. When displayed mid-line in an
Incorrect format line: , we see, well, that. Fixing #215 should make this a non-issue.yakra commentedon Apr 15, 2020
Definitely the case for Incorrect format lines. Theoretically, the user can see that the number of fields in the line is wrong, and will know what to fix. Or maybe the line is just intended as a comment, without using
#.This junk isn't very helpful.
OTOH:
This looks a little nefarious. That's
0x1F, the ascii field separator. No idea how it got in there, but...Firefox & Chromium won't treat this as a regular text file; I'm prompted to download it & either open or save.
When chaddean opens it up in a text editor, it's possible he won't see any indication of the stray character at all. It may just be blank. He could see the error line and say, "What the heck? Looks like a perfectly fine waypoint label to me."
So, there could be some use for taking this approach when a control character is part of a region, route or label field.
These errors are rare; these are the only 2 user log files containing non-ascii characters. I'll fix the Incorrect format line cases, and go no-build on the others for now while giving a bit more thought to how to handle them.
Heh -- lowenbrau.list somehow has a bunch of extra null
\0s at the end of a file. If a null\0ever makes its way into the middle of a file, all hell will break loose. I hope that never happens.yakra commentedon Apr 15, 2020
It makes sense to replace characters and add a note when control characters (<
0x20) are included.But it does not make sense to replace characters >
0x7F, which are probably going to be part of international characters.yakra commentedon Apr 15, 2020
Going full bore with mitigating any null
\0s is overkill when as it stands this is essentially a fix for an oddity in a single file -- multiple or much more complicatedstrips, and then treating them as a delimiter ...On the C++ side, we're not using
strtokto separate lines anymore, so a potential rewrite would be simpler. But still.Similar to removing the BOM from the first line only, we can
rstrip('\x00')from the last line only, and save some processing time on the rest.yakra commentedon Apr 15, 2020
No difference in speed. I'll keep it about as it is, for that extra little bit of robustness.