Skip to content

MALFORMED_LAT, MALFORMED_LON & LABEL_TOO_LONG robustness #302

Closed

Description

@yakra

Need to take care to get the MALFORMED_LAT, MALFORMED_LON & LABEL_TOO_LONG datachecks right. Data inserted into datacheckErrors.label1 and datacheckErrors.value must be neither:

  • overlength
  • truncated in the middle of a multi-byte character

It's very rare that this would actually happen, but gotta do it right.


LABEL_TOO_LONG cases should be ignored, similar to the malformed URL cases.
Rationale: To not ignore it means putting it in the DB, which means truncating the label to something of legal length. This truncated label could then end up in a .list file, and thus pointsinuse.log. Copying from there and pasting into wptedit would not flag the label as in-use, because the full label from the .wpt code doesn't match the truncated one from pointsinuse.log. It could too easily lead us to breaking .list files.

Activity

  1. yakra commented on Apr 4, 2020

    @yakra
    ContributorAuthor

    LABEL_TOO_LONG

    • Python
    # some constants to get this code to work standalone in the python3 terminal
    label = "12345678901234567890ññ3456789012345678901234567890"  # pick one
    #label = "12345678901234567890ññ345678901234567890123456789"  # pick one
    class DBFieldLength:
        label = 26
        dcErrValue = 32
    ############################################################################
    
    slicepoint = DBFieldLength.label-3
    while len(label[:slicepoint].encode('utf-8')) > DBFieldLength.label-3:
        slicepoint -= 1
    
    print('"'+label[:slicepoint]+'..." goes into [datacheckErrors.label1]')
    excess = "..."+label[slicepoint:]
    print(excess)
    
    if len(excess.encode('utf-8')) > DBFieldLength.dcErrValue:
        slicepoint = DBFieldLength.dcErrValue-3
        while len(excess[:slicepoint].encode('utf-8')) > DBFieldLength.dcErrValue-3:
            slicepoint -= 1
        excess = excess[:slicepoint]+"..."
    
    print(excess)

    ...all this because there's no way to take a string and slice it at an arbitrary byte boundary. I can convert to a bytearray, but if that's sliced mid-character, I can't convert it back to a string. And I can write strings xor bytearrays to a file, but not a mix of both, it appears. What a pain in the...wow.

    C++, OTOH? On further thought, cutting the strings mid-character matters less. These points will be ignored & not make it into the HB or .lists, just shown on datacheck.php. Since the point doesn't make it as far as the LABEL_INVALID_CHAR datacheck, a � will give a bit more of an indication that, like with any multi-byte character, we have an invalid character.

    So I'll just handle Python & C++ differently, whatever gets the job done most conveniently in each language.

  2. reopened this on Apr 5, 2020
  3. yakra commented on Apr 5, 2020

    @yakra
    ContributorAuthor

    Replacing waypoint labels in me.me188.wpt with

    x()------1---------2----26
    0()------1---------2-----27
    1()------1---------2-23---------1---------2---------3---------4---------5----56
    2()------1---------2-23---------1---------2---------3---------4---------5-----57
    3()------1---------2-----é
    4()------1---------2-23---------1---------2---------3---------4---------5----é
    5()------1---------2-23---------1---------2---------3---------4---------5-----é
    6()------1---------2--é---------1---------2---------3---------4---------5----56
    7()------1---------2--é---------1---------2---------3---------4---------5-----57
    8()------1---------2--é---------1---------2---------3---------4---------5----é
    9()------1---------2--é---------1---------2---------3---------4---------5-----é
    A()------1---------2--é---------1---------2---------3---------4---------5---é
    B()------1---------2--é---------1---------2---------3---------4---------5--é
    C(-------1---------2--é---------1---------2---------3---------4---------5---)
    
    • Python: Points are ignored, but the DatacheckEntrys don't make it to the datacheckerrors list. Edt: They did, only flagged for a completely different route. Wow, Python. Variables. Scope.
    • C++: Crap! Apparently MySQL 8.0 doesn't like the C3 byte when it's not part of a UTF-8 char. I'll keep it simple & just cut the string where I cut it, removing everything >7F from the end of datacheckErrors.label1 & the beginning of datacheckErrors.value.
  4. yakra commented on Apr 9, 2020

    @yakra
    ContributorAuthor

    Python malformed URL checks still don't account for multi-byte chars driving the byte count too high.

    Edit: Ack, but does it matter though?
    Right now siteupdate.py counts multi-byte chars toward the total char counts, without splitting them.

    • MySQL 5.7 will truncate mid-char, we'll see a garbage half-character on datacheck.php, and everything's grand.
    • MySQL 8 tolerates multi-byte chars.
    • What about MariaDB, or whatever other software a web admin may choose to use?

    Will go no-build pending a cleanup per #299.

  5. reopened this on Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions