News for hackers. Stuff that matters.
Re:What can’t the internet handle in 2022? Apostrophes by colejohnson66 on Monday October 03, 2022 @09:54PM (#33075976)
Once again, programmers forget alphabets other than the Latin one exist. And by Latin, I mean the one containing only A through Z, with no “fancies”.

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/

Re:What can’t the internet handle in 2022? Apostrophes by ranger_danger on Tuesday October 04, 2022 @02:42AM (#33077263)
Most of us realize that other encodings and alphabets exist, it's just that supporting them is a nightmare. Do you have any idea how many un-typeable, invisible Unicode control characters there are? Did you know you can display the same Unicode text using different byte combinations?

How on Earth are devs supposed to sanitize this??

Re:What can’t the internet handle in 2022? Apostrophes by acdha on Tuesday October 04, 2022 @12:37PM (#33082865)
> 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.

Re:What can’t the internet handle in 2022? Apostrophes by colejohnson66 on Tuesday October 04, 2022 @09:05AM (#33079746)
Unicode themselves provide algorithms on handling them. There are libraries that implement these algorithms. Use them; Don't roll your own.
Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @10:53AM (#33081257)
The libraries are not good. Support for the libraries in runtimes varies wildly and has drastic performance implications: unicode has variable width characters, so sometimes character array indexes are no longer O(1)!

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.

Re:What can’t the internet handle in 2022? Apostrophes by tialaramex on Tuesday October 04, 2022 @11:19AM (#33081612)
> what encoding is it in?

UTF-8. Unless you've got clear directions that it needs to be something else, the correct choice is always UTF-8. Stop emitting things in other encodings, "Doctor it hurts when I stab myself with this knife". Yes it does, so don't.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:21AM (#33081651)
That's a great guess, but my point is that it's a guess. It will sometimes be wrong, and when the guess is wrong you will have articles like the above written complaining about the fallout.

These types of errors are guaranteed specifically because of the policy of guessing and loose heuristics you're describing.

Re:What can’t the internet handle in 2022? Apostrophes by GoblinSlayer on Tuesday October 04, 2022 @01:36PM (#33083808)
Unicode fixes it. It's why legacy encodings are unworkable.
Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @05:29PM (#33087241)
Unicode absolutely does not fix the issue of not knowing the encoding of a legacy byte buffer with text in it.
Re:What can’t the internet handle in 2022? Apostrophes by cedilla on Tuesday October 04, 2022 @11:49AM (#33082138)
> unicode has variable width characters, so sometimes character array indexes are no longer O(1)!

> Unicode is not a good system.

Unicode is excellent. Your gripe is with human languages and their scripts. It wasn't the Unicode consortium who decided that some scripts have oddities like single glyphs that can encode anything between a single sound and a whole sentence, or oddities like different 'cases' where glyphs change form just because they happen to be at the beginning of a sentence or proper noun

Re:What can’t the internet handle in 2022? Apostrophes by dontlaugh on Tuesday October 04, 2022 @11:03AM (#33081390)
Why would you index into a "character array"?

Also, what is a "character" to you?

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:16AM (#33081565)
> Why would you index into a "character array"?

Obviously, because you need to examine characters. Here are a couple examples:

* You're implementing any software that deals with rfc6531 compliant email. You'll need to parse strings as unicode to understand where to route mail, for example to understand 你好@example.com

* You're implementing a database, or any software with a search function which indexes unicode fields. You'll have to understand the logical character structure of the data, or your searches won't match properly.

> Also, what is a "character" to you?

Characters are defined by the unicode specification. In UTF8 they can be represented by multi-byte sequences. Using the example of 你好@example.com, the @ is the seventh byte position, but the third character position. You cannot implement software that handles internationalized emails without parsing and understanding strings like this.

Re:What can’t the internet handle in 2022? Apostrophes by tialaramex on Tuesday October 04, 2022 @11:28AM (#33081767)
> Characters are defined by the unicode specification.

Unicode's glossary offers four definitions for this word, which ought to be a strong hint that this is not a technical term but instead a vague idea people have which doesn't align very well to the technical problem.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:34AM (#33081857)
As I said initially: The interface (including the underlying unicode specification) is not good.

This is precisely my point. Internationalization is building on a foundation of sand.

Re:What can’t the internet handle in 2022? Apostrophes by dontlaugh on Tuesday October 04, 2022 @11:47AM (#33082094)
That's not how you'd parse email. In fact, the bit before @ is encoded differently from the bit after @.

You're much more likely to iterate over elements in a string than index. You might iterate over code points, abstract characters, glyphs, grapheme clusters, etc. You might do it before or after a certain kind of normalisation. Since there are many ways to split a string (depending on what you're doing), it won't be possible to make all of them have O(1) indexing.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:49AM (#33082141)
What do you mean "that's not how you'd parse email?" I didn't describe an algorithm.

Why don't you explain how you would parse the above email address without understanding the unicode encoding?

Re:What can’t the internet handle in 2022? Apostrophes by colejohnson66 on Tuesday October 04, 2022 @01:06PM (#33083329)
If you're asking how to get everything after the '@' symbol, you can use knowledge of UTF-8 (assuming your byte array is UTF-8) to just say `FindIndexOfByte(utf8Buffer, (byte)'@') + 1`. But treat everything else as an opaque blob. The URL portion of that email address, as far as you should be concerned, it just the bytes after the '@' symbol. If you want to verify if it's a valid URL, you should use a URL library, not some hack that assumes a TLD is 3+ characters. However, even that naive method of a byte search is wrong. According to RFC 2822, '@' symbol is actually allowed on the left hand side if escaped. You should be using an email parsing library that implements the spec properly.

Naming the smallest unit of information in C a 'char' was a terrible mistake made decades ago. A character has never been a single byte in many countries. Shift-JIS, for example, can be one or two bytes, and it's two and a half decades old. Even in UTF-16 (used by Java and C#), a 'char' isn't actually a character, but a codepoint. One that could even be an unpaired surrogate.

Really, you should never be indexing into the backing byte/char array unless you know what you're doing. If you think you need to, you should be asking yourself, "what is it I really need to do?" Because you, as a programmer dealing with internationalization, must not assume English/Western ideas about language. For example, in abugidas[0], a single word can be a whole sentence. For a more common language, Japanese typically doesn't use spaces because they're not needed when writing kanji. But that's not foolproof because hiragana and katakana aren't for words, but sounds. How do you do a word count in those languages? You don't.

[0]: https://en.wikipedia.org/wiki/Abugida

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @04:52PM (#33086651)
> You should be using an email parsing library that implements the spec properly.

> you should use a URL library, not some hack

I think what you're somehow missing is that I am specifically offering authoring an email parsing library (or URLs, or whatever) as an example of where things break down.

Your answer is essentially "let someone else program it, because it's complicated and fraught with peril" -- but my entire point is that it's complicated and fraught with peril.

You are agreeing with me, and your post is a fine example of why the interfaces are bad and error prone.

Re:What can’t the internet handle in 2022? Apostrophes by colejohnson66 on Tuesday October 04, 2022 @05:03PM (#33086843)
> Your answer is essentially "let someone else program it, because it's complicated and fraught with peril" -- but my entire point is that it's complicated and fraught with peril.

Are you asking how one would write code for the libraries you should use? In general, there already is one: ICU.[0] But if you had to write your own, as I said above, Unicode provides algorithms[1] that one might want to implement, in addition to a massive (over 1000 page) spec[2] detailing how to handle the various languages. For example, if you need to write the code to handle bidirectional text, there's UAX/TR #9[3]. Want to implement case changing? See Chapter 3.[4]

There's also the Unicode Character Database[5] that contains information on every code point. Your library/program would need to hold a copy of this whole thing.

[0]: https://icu.unicode.org/

[1]: https://unicode.org/reports/

[2]: https://www.unicode.org/versions/Unicode15.0.0/

[3]: https://unicode.org/reports/tr9/

[4]: https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf

[5]: https://www.unicode.org/reports/tr44/tr44-30.html

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @05:33PM (#33087301)
No. Let's do a quick recap:

You said that people ought never address text by characters or bytes.

I'm pointing out that this is nonsense and I offered several examples.

You responded saying basically that those tasks are complex and someone else should do it.

In your followup response, you recommend using ICU which ... has an interface for iterating by character. Which is all I had mentioned to begin with. Sigh.

Re:What can’t the internet handle in 2022? Apostrophes by withinboredom on Tuesday October 04, 2022 @03:22PM (#33085401)
Why the hell do you need to route the email unless you’re working on an email server? Send the email and have the user validate it. If they validate it, it’s a valid email. Don’t be clever, be smart.

Even if you’re working on an email server, you shouldn’t be touching that code unless it’s broken or you’re writing an implementation from scratch. In that case, treat it as an opaque blob.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @04:33PM (#33086396)
> unless you’re working on an email server?

We are talking about email software, inclusive of servers, clients, plugins, etc. It's literally the example I'm offering (but there are neigh infinite others)

> Send the email and have the user validate it. I

But I haven't proposed a problem of validating an email. Besides, even if the problem is validating an email this is not necessarily a workable answer.

> Even if you’re working on an email server, you shouldn’t be touching that code unless it’s broken

A lot of the arguments supporting unicode seem to boil down to acknowledging that all these things are broken, yet disregarding them because the problems exist at a more technical level than most of HN commenters are familiar with.

You might not write this kind of software for a living, but some of us do and we know that these interfaces are not good.

Re:What can’t the internet handle in 2022? Apostrophes by cxr on Tuesday October 04, 2022 @04:53AM (#33077914)
This comment is taking on flak, but Wirth &co took a similar stance, even as Zürchers.
Re:What can’t the internet handle in 2022? Apostrophes by jayd16 on Tuesday October 04, 2022 @12:06PM (#33082390)
>Did you know you can display the same Unicode text using different byte combinations?

Even ASCII has upper and lower case letters. Languages are hard.

Re:What can’t the internet handle in 2022? Apostrophes by IshKebab on Tuesday October 04, 2022 @05:18AM (#33078060)
I definitely agree. The article even mentions someone with a diaeresis in their name, which is distinct from an umlaut. Good luck sorting that mess out.

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.

Re:What can’t the internet handle in 2022? Apostrophes by GoblinSlayer on Tuesday October 04, 2022 @06:13AM (#33078349)
It's inert text, query parameters will sanitize it for you.
Re:What can’t the internet handle in 2022? Apostrophes by JTbane on Tuesday October 04, 2022 @10:33AM (#33080948)
It's only inert if you're not transforming it (for example, calling toLower on all strings passed in) or doing equality checks. Many applications use these and it is a minefield in Unicode.
Re:What can’t the internet handle in 2022? Apostrophes by tialaramex on Tuesday October 04, 2022 @10:54AM (#33081272)
But what's the semantic purpose of these operations? Linguistically these are very strange things to do to arbitrary text, and yet because in ASCII it was easy, programmers got into the habit of just doing it all over the place without thinking about what (if anything) it meant.

For transform operations like "toLower" often it turns out that to the extent it means anything it's only relevant to ASCII and so an operation which only transforms ASCII is appropriate anyway.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:06AM (#33081437)
> But what's the semantic purpose of these operations?

The list is infinite, but let's use a very simple one which is the focus of this article: Names of things.

You name a file on a case insensitive filesystem. Should the case insensitivity only apply to certain encodings, or all of them? You'll need to do a case transformation and string comparison to make this work.

You create an email address, per rfc6531. You'll need to deal with case flattening, string comparisons, and lexical parsing.

These are not strange operations. These are not only common they are obviously required operations, because names identify things and names (eg emails) are often structured and must be parsed and understood.

Can you imagine the fallout if software developers said "sorry, you can only search for ASCII names because we think indexing unicode strings is a very strange thing to do?"

Re:What can’t the internet handle in 2022? Apostrophes by tialaramex on Tuesday October 04, 2022 @11:40AM (#33081957)
> You'll need to do a case transformation and string comparison to make this work.

Better to say you need a canonicalisation table and you will need to canonicalise the text. NTFS filesystems actually carry their canonicalisation table with them, so if you happen to be using a USB drive with an NTFS filesystem where Z and Q are just different versions of the same hypothetical "Q-Z" character, filenames ZZ150 and QQ150 are indistinguishable on that USB drive, even though your Windows PC has no trouble distinguishing Z from Q.

Notice that unlike "case transformation" this doesn't pretend we're doing something with larger semantic value, and indeed the actual names on disk aren't promised to be Unicode text under NTFS, they're just arbitrary 16-bit values which probably make sense as UCS-2 or these days UTF-16 when rendered, the tables just convert some values into others.

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @11:47AM (#33082095)
Do you understand that filesystem drivers are yet another example of places where software developers need to do these types of operations which you're dismissing as "very strange things?"

How do you propose that I, a person who among other things develops filesystems, implement a canonicalization table without doing these "very strange things?"

Furthermore, filesystem operations are not limited to calls into the filesystem driver. Programs often need to deal with paths outside of filesystem calls: The names of files need to be displayed on screens. They need to be indexed in databases and searched for. They need to be encapsulated within other protocols and data formats and often need to be parsed and understood.

You are essentially agreeing with me that these are normal, necessary things. Your position appears to be "someone else does that type of thing for me," which is not a very compelling argument.

Re:What can’t the internet handle in 2022? Apostrophes by GoblinSlayer on Tuesday October 04, 2022 @01:18PM (#33083516)
Case insensitive file systems might as well be a historic accident, because lower case letters didn't always exist and then it was kept for backward compatibility.
Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @05:28PM (#33087227)
Case insensitive functions are common. Filesystems are just one of many places where this kind of function is expected.

It's just a particularly common canonicalization function. Canonicalization is a common need across all languages as we've already clearly established.

Re:What can’t the internet handle in 2022? Apostrophes by GoblinSlayer on Tuesday October 04, 2022 @12:24PM (#33082682)
I think you shouldn't try to reproduce the filesystem name comparison algorithm. Check if file exists or generate numeric name.

I can't find where rfc6531 requires case flattening. The word "case" is used there in the meaning of "situation".

Re:What can’t the internet handle in 2022? Apostrophes by throwaway09223 on Tuesday October 04, 2022 @04:29PM (#33086339)
Case sensitivity is addressed in other RFCs relating to email and DNS.

> Check if file exists or generate numeric name.

Nonsense. You may not be in control of the names, and checking a file with stat(2) may not address the problem at hand (and: is many orders of magnitude different in cost as well).

Re:What can’t the internet handle in 2022? Apostrophes by GoblinSlayer on Tuesday October 04, 2022 @11:43AM (#33082028)
I imagine those applications have a better idea what sanitation they need. Is it even the same for all of them? And toLower is what they do now, but how do you predict the algorithm won't change in future? When you sanitize proactively for future algorithms, it's just data loss.
Re:What can’t the internet handle in 2022? Apostrophes by rsynnott on Tuesday October 04, 2022 @10:32AM (#33080938)
> but it’s actually a UTF-8/Windows-1252 issue.

Or possibly ISO-8859-1, which is, helpfully, slightly different.

Re:What can’t the internet handle in 2022? Apostrophes by colejohnson66 on Tuesday October 04, 2022 @01:18PM (#33083514)
True. But, in this case, I'm betting it's Windows-1252. The character in Ch'ien's name is most likely `U+2099 RIGHT SINGLE QUOTATION MARK`. In UTF-8, that's `E2 80 99`. ISO-8859-1 doesn't have 80 or 99 defined, but Windows-1252 would decode it to ’ (what's on the card).
Re:What can’t the internet handle in 2022? Apostrophes by mc32 on Monday October 03, 2022 @10:28PM (#33076137)
I want URLs that handle spaces. Like I could enter www.coca cola.com. [and not www.coca-cola.com. nor www.cocacola.com.) and it would work. "Simple space". Even the Latin/Roman alpha had space(s).
Re:What can’t the internet handle in 2022? Apostrophes by ly3xqhl8g9 on Tuesday October 04, 2022 @03:05AM (#33077367)
The Romans wrotewithoutspaces as in "continuous script" [1], however they·did·use·the·interpunct for delineation on inscriptions. In order to have spaces in domain names we would need to use another sign, such as • [2], to separate words and avoid ambiguity.

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

Re:What can’t the internet handle in 2022? Apostrophes by OJFord on Tuesday October 04, 2022 @04:26AM (#33077756)
Is that ever ambiguous in Latin, or is there enough variation in declensions and conjugations (and enough of them) that the word endings are always clear?
Re:What can’t the internet handle in 2022? Apostrophes by ly3xqhl8g9 on Tuesday October 04, 2022 @05:12AM (#33078019)
Quote from Wikipedia: 'For example, a phrase written in scriptio continua as collectamexiliopubem may be interpreted as collectam ex Ilio pubem, meaning "a people gathered from Troy", or collectam exilio pubem, "a people gathered for exile". Thus, readers had to be much more cognisant of the context to which the text referred.' As in everything, context rules over content.
Re:What can’t the internet handle in 2022? Apostrophes by teeray on Monday October 03, 2022 @10:40PM (#33076199)
www.google.com [a ton of spaces that HN won’t let me type] jknotgoogle.com
Re:What can’t the internet handle in 2022? Apostrophes by notamy on Tuesday October 04, 2022 @11:03AM (#33081383)
Domain registration already has a lot of rules around length, what characters can be where in the domain name (ex. no hyphens as the very first/last characters), ... I'm sure it'd be trivial to have a "no-repeating-spaces" rule or similar.
Re:What can’t the internet handle in 2022? Apostrophes by karatinversion on Tuesday October 04, 2022 @11:42AM (#33082004)
google.com [spaces] pwned.evilcorp.com it is
Re:What can’t the internet handle in 2022? Apostrophes by mc32 on Monday October 03, 2022 @10:45PM (#33076223)
I just want a single contiguous space character so I don't have to suppress the space or substitute with an alternate character --also URL boxes can make it conspicuously obvious for better UI. And while they're at it, allow & (ampersand).
Re:What can’t the internet handle in 2022? Apostrophes by andrewxhonson on Monday October 03, 2022 @11:47PM (#33076527)
Maybe the location bar should accept the space but strip it? That would work for input if not reading the URL. Maybe only allowing single consecutive spaces to avoid the address spoofing example. I could go for that.

I would love & natively though. For my wedding (bride&groom.com for example) I looked into faking it with punycode but nothing was close enough, and anything other than an ampersand would have been too hard to input.

Re:What can’t the internet handle in 2022? Apostrophes by armchairhacker on Monday October 03, 2022 @10:55PM (#33076269)
good think hyperlinks are typically underlined so there will be a large training line at the end
Re:What can’t the internet handle in 2022? Apostrophes by astine on Monday October 03, 2022 @11:16PM (#33076368)
Unless someone turns off the underlining with a stylesheet.
Re:What can’t the internet handle in 2022? Apostrophes by thatguy0900 on Tuesday October 04, 2022 @10:31AM (#33080915)
Google search urls are typically long enough that they are shortened by ... At least on mobile
Re:What can’t the internet handle in 2022? Apostrophes by mminer237 on Tuesday October 04, 2022 @11:01AM (#33081361)
You can have spaces in URLs: https://matthewminer.name/spaced%20name

You just can't have them in domain names.

Re:What can’t the internet handle in 2022? Apostrophes by mc32 on Tuesday October 04, 2022 @11:35AM (#33081890)
Sure, I meant the whole URL, including the domain portion as in my example.
Re:What can’t the internet handle in 2022? Apostrophes by gumby on Tuesday October 04, 2022 @02:28AM (#33077192)
Space is perfectly legal in URLs, but not in a domain name so your example won’t work for that reason.
Re:What can’t the internet handle in 2022? Apostrophes by cxr on Tuesday October 04, 2022 @11:27AM (#33081746)
> Like I could enter www.coca cola.com. [and not www.coca-cola.com

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