Skip to content

Check for non-ASCII entries in wpt, list files #41

Closed

Description

@jteresco

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.

Activity

  1. self-assigned this
    on Dec 18, 2016
  2. yakra commented on Dec 21, 2018

    @yakra
    Contributor

    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?
  3. michihdeu commented on Dec 21, 2018

    @michihdeu
    Contributor

    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.

  4. jteresco commented on Dec 21, 2018

    @jteresco
    ContributorAuthor

    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.

  5. yakra commented on Dec 30, 2018

    @yakra
    Contributor

    @yakra wrote:

    This leaves us with just AltLabels. Are there even any known AltLabels with non-ASCII characters currently?

    Confirmed, there are none.

    @michihdeu wrote:

    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.

    @jteresco wrote:

    Non-ASCII characters used to cause problems in site updates on FreeBSD before the utf-8 setting allowed that.

    Now that we use this option, non-ASCII characters are much less of a showstopper.

    @michihdeu wrote:

    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.

  6. michihdeu commented on Dec 30, 2018

    @michihdeu
    Contributor

    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.

    I didn't know that. I understand now why my previous post was... kind of useless 😃

  7. yakra commented on Dec 30, 2018

    @yakra
    Contributor

    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;

  8. self-assigned this
    on Dec 30, 2018
  9. yakra commented on Jan 2, 2019

    @yakra
    Contributor
  10. yakra commented on Jan 11, 2019

    @yakra
    Contributor

    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 2019
    52,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
  11. yakra commented on Jan 22, 2019

    @yakra
    Contributor

    #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?

  12. yakra commented on Mar 12, 2019

    @yakra
    Contributor
    • in a line with <> 4 non-comment fields, and thus ignored,

    This would trigger the Incorrect format line: error, and output the offending line to the .log

    • 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.

    This can all result in control / non-ASCII characters in log files, which can prevent some text editors from reading them.

  13. yakra commented on Mar 12, 2019

    @yakra
    Contributor
  14. yakra commented on Apr 14, 2020

    @yakra
    Contributor

    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.

    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?

  15. jteresco commented on Apr 14, 2020

    @jteresco
    ContributorAuthor

    I agree a .log with the actual offending text will be more useful to a user. I am fine with what you propose.

  16. yakra commented on Apr 14, 2020

    @yakra
    Contributor

    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.

  17. yakra commented on Apr 15, 2020

    @yakra
    Contributor

    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.

  18. yakra commented on Apr 15, 2020

    @yakra
    Contributor
    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.

    philimon.log:
    49c49
    < Unknown region/highway combo in line: //GRC EO03 Μπράλος Θερμοπύλες
    ---
    > Unknown region/highway combo in line: //GRC EO03 ?????????????? ???????????????????? [line contains invalid character(s)]

    But it does not make sense to replace characters > 0x7F, which are probably going to be part of international characters.

  19. yakra commented on Apr 15, 2020

    @yakra
    Contributor

    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.

  20. yakra commented on Apr 15, 2020

    @yakra
    Contributor

    No difference in speed. I'll keep it about as it is, for that extra little bit of robustness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions