85 points · by lxm · 4y ago · 145 comments
Then there’s the issue of character encodings, which the article does a decent job explaining! Nitpick though: they claims it’s a UTF-8/ASCII thing, but it’s actually a UTF-8/Windows-1252 issue.
In related news, even GNU coreutils fails to support UTF-8 properly despite a claim of support for multibyte character sets: https://catgirl.ai/log/cut-c-harmful/
How on Earth are devs supposed to sanitize this??
By using the widely-available free tools which are near universal by now? This hasn't been technically _hard_ since around the turn of the century[1] but developers, especially Americans, have been lazy and tried to avoid doing the work needed to get beyond C-style string handling or, in the case of the apostrophes, using parameterized queries.
1. Having build a site which supported English, both simplified and traditional Chinese, Thai, and Vietnamese (including what passed for webfonts back then) in the 90s, I know how bad it used to be but also that was 3 decades ago.
Unicode is not a good system. Yes, we can struggle with it but it will always be a struggle because of the nature of its design.
A major omission is a way to indicate the encoding of a particular byte array. You open a file on disk and read its characters -- what encoding is it in? What encoding is used for the various buffers embedded in dozens of historic file formats for audio, video, archives, etc?
Developers are forced to guess and hack. The results are about as expected, given the quality of the underlying interfaces.
That said, you could clearly whitelist a much more reasonable range of characters than just the Latin alphabet. Hypens, apostrophes, common accented letters etc. should probably all be allowed. There are standard algorithms for canonicalising the unicode representation of them.
Even ASCII has upper and lower case letters. Languages are hard.
Or possibly ISO-8859-1, which is, helpfully, slightly different.
[1] https://en.wikipedia.org/wiki/Scriptio_continua
[2] The bullet • (U+2022) alt code is 7, or Opt + 8 on Mac. The interpunct · (U+00B7) alt code is 250, or Shift + Opt + 9 on Mac. Rather inconvenient for the regular user.
You just can't have them in domain names.
Aside from all the comments about what's wrong with this on a technical level, this is a poor example since the product name is actually "Coca-Cola" and not "Coca Cola".
In print, code is often represented in a monospace font, materials intended for beginners sometimes indicate stuff that you are actually supposed to type with little keycap symbols, etc. Have there been any programming languages (with associated IDE:s) where strings were represented by typography (or colour, or whatever) rather than by surrounding them with some sort of quotation marks?
99% of programmers shouldn't be treating text as anything but opaque blobs of data that, when sent to a rendering function, become readable by users. Don't try to take text blobs apart and make assumptions about their binary structure. We should not be looking under the hood and trying to divine things like how many letters are in them (what's a letter?) or trying to manually transform them in some way (case, splitting, concatenation, input sanitization and so on). Use tried and true libraries for these. Same for when you need to transform it into some particular encoding. The only safe question to ask of text is "how much memory does this thing use?"
It is truly a minefield, but it's a minefield that developers are expected to understand and navigate. "Text in different encodings are scary outliers that we shouldn't support" is pee-wee league level software engineering.
1: https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...
I'm not even talking about a full 4-year course, the majority of stupid moves in programming can be taught away in a course that's a few weeks of learning, especially once you've had a bunch of experience already.
Like a coursera course titled "How not to be dumb at coding"out something of the sorts.
https://duckduckgo.com/?q=falsehoods+programmers+believe+abo...
It's infuriating, I've seriously considered changing my name because of it.
Sometimes it's due to a legacy back-end system dating back to the 1990's or earlier, so they have to strip out "bad" characters before sending the order or contact form through.
It's like those infuriating bank / other websites that truncate passwords on login forms but not on the password change form.
On the plus side, you have a strong privacy guarantee :)
Ben Dover, Hashtag Follow, Destinee Hooker, Khumalo Tiny Dick, Guy Nutter
Guilherme Crabogiale Fuck, Jurassic Park, Beautiful Existence, Tokyo Sexwale, Mike Litoris, Batman Bin Suparman, Jesus Condom
Mrs. Rape, Kash Register, Donald Duck, Robert Fagot, Tatiana Vagina, Hitler Mussolini.
This output is is then later re-parsed, and to try to restore null inputs back to being null, the code matches on the string "null", ignoring the fact that that could have been a valid string itself.
O'Rourke = Ó Ruairc
O'Reilly = Ó Raghallaigh
O'Donovan = Ó Donnabháin
So you could get rid of the apostrophe and at the same time really spice your name up, perhaps.
E-mail is even worse than web applications at this because even common and popular mail clients can't do UTF-8 in email addresses right (https://www.google.com/search?q="SMTPUTF8"+site%3Adovecot.or...).
I'm pleasantly surprised about SMTPUTF8 being a thing though. Yeah nobody uses it, but I thought email had zero UTF-8 support so it's at least better than nothing, I guess.
[1] https://en.wikipedia.org/wiki/IDN_homograph_attack#Homograph...
It's cumbersome at times, but a perfectly reasonable tradeoff in my opinion. Some libraries add other string types when they're needed to interact with a system. For example, the windows crate has wide strings.
type SanitizedString = string
And somewhere you have a function getSanitizedString and if you don't call that the type system will complain.Same could be done to represent a distance in Km or miles:
type DistanceKm = number
type DistanceMiles = number
And then functions can explicitly use any of them or only some (we could define some function multiplying them to allow 2 arguments only if they are the same type).It’s bad enough that apparently no one can spell my name correctly but when my partner and family with letters such as ö or ł can almost never type their correct name it irritates me greatly.
A few months ago at work I had to actually kick off at product managers and QA that these letters are not “special characters” in the same way ? or & are. In the end I had to refuse to implement the regex in the form validation and just said that it was done and that was the end of it. So incredibly dumb that peoples names are classified as “special characters” by some arbitrary set of rules people subscribe to.
It's like when you travel and you start to judge gas stations by their bathroom. Anyone who has traveled a lot knows exactly what I mean.
copy/paste worked more reliably 20 years ago than it does today. So much so that I've started judging software based upon their ability to reliably copy/paste. Seems stupid, right? Just like judging gas stations by their bathroom seems stupid to people who rarely go into them because they don't travel.
But it flat out amazes me how bad copy/paste is today.
I once spent _hours_ trying to figure out why a PHP script was shitting all over itself. It turns out I copy/pasted the email text from Monday.com and it copied non-printing characters that caused PHP to fall over.
Thing is, at that point, I was an old hand at that stupid crap, it didn't take me that long to find it. I learned years ago not to trust copy/paste.
Here's my swat at the puzzle:
https://whitemagicsoftware.com/keenquotes/
When exporting Markdown documents to HTML or PDF, my text editor uses KeenQuotes to curl straight quotes to their most likely candidate:
Expected output: „Goedemorgen,” zei hij.
Returned output: “Goedemorgen,” zei hij.
And that's just language to take care of! Smart quotes for computers are hell and there should be a library to do all this so everyone doesn't need to reinvent the wheel.
Every tangle I've ever had with IEEE 754 would have been unnecessary if our computers and languages used the same numbers that humans do! (And we have way more than enough compute power now to make Base10 arithmetic the default - I'll cut the folks in the '60s some slack due to resource limits, but why are we still dealing with this brokenness in the 21st century?)
If you want base-10 encoding of non-integer values, and base-10 arithmetic on them, you're probably going to need a software library like [1], which implements the decimal math that is also in IEEE754, just not part of common hardware. It also may be that you actually want infinite-precision arithmetic, which definitely requires a library, because the representation of a number becomes its own dynamic data structure (like with a string).
Can you say more about what exactly is the "brokenness" that you're running up against?
[1] https://www.intel.com/content/www/us/en/developer/articles/t...
One of the vexing things about MS Outlook and Exchange is that they insist on using a non-standard syntax in which ' is used as a quote, so they make an appalling mess of mail headers.
They're not. You should be more than just tempted to use ' (U+0027 APOSTROPHE) for apostrophe, because it is. Closing single quotation mark is ’ U+2019 RIGHT SINGLE QUOTATION MARK.
https://www.unicode.org/versions/Unicode14.0.0/ch06.pdf
Typographically, U+2019 is the appropriate glyph for quotation marks in English and in some other western languages.
It would be forgiven for rejecting an evil string, but names with apostrophes must be handled.
https://gdprhub.eu/index.php?title=Court_of_Appeal_of_Brusse...
Robert'); DROP TABLE Students;-- https://xkcd.com/327/
Why in the world am I having to protect the project from such things? I understand ignorance, but the person putting together the base of the project should know what the hell is going on.