Live data from Hacker News

The Safari bug that never was (2022)

obyford.com

51–60 of 94 posts

Re: The Safari bug that never was (2022)

#51
post #32

FTA: “And in the font we use on GOV.UK, the new line character has a bigger width than a space character – which is apparently unusual. […] One of them incorrectly used the width of the new line character in its calculations, and so the box that it made was too small.” I don’t understand that explanation. If the newline character in the font is wider than a space, why would the box end up too small if width calculati…

That GitHub issue has a link labeled upstream bug pointing to: https://bugs.webkit.org/show_bug.cgi?id=232939 Not sure if that helps answer your question though

The answer to the question appears to be in comment 13; the width of the newline character is used at one point but then assumed to be the same as the width of a space later on:

> I think I see. There's a block at the bottom of RenderText::computePreferredLogicalWidths() which is only hit if wordLen == 0 and !isNewline (which is the case here) which measures the width of the one character at index i and adds it to currMaxWidth. In our situation, that's the leading newline character.

> Then, later, we subtract it out like this: "widths.max -= font.width(RenderBlock::constructTextRun(&space, 1, style));". This expects that the width of this initial character is equal to the width of a space.

Re: The Safari bug that never was (2022)

#53
post #50
post #32

FTA: “And in the font we use on GOV.UK, the new line character has a bigger width than a space character – which is apparently unusual. […] One of them incorrectly used the width of the new line character in its calculations, and so the box that it made was too small.” I don’t understand that explanation. If the newline character in the font is wider than a space, why would the box end up too small if width calculati…

The way I understood it in my head (though I don’t know if the article actually says this) is that process that figured out the box size was probably ignoring the new line and just assuming it was the same width as a space. The process that actually laid out the text was using the specified width of the new line, so it came up with a longer width and had to break the line.

But the thing is: as the article (correctly) says:

“In HTML, any extra whitespace between words is ignored. This means you can add extra spaces, and even new lines, between words without affecting how they are displayed in the browser”

So, “ignoring the new line and just assuming it was the same width as a space” is correct behaviour.

I now think what happened is this:

- the width of the box to render the text in was computed correctly

- the code that then laid out the text inside that box incorrectly used the width of the newline in the HTML to compute the length of the text, concluded the text was too long to fit on a line, and line-wrapped it inside the box.

That’s not consistent with the claim from the article “and so the box that it made was too small”, though.

Alternatively, the font’s line feed glyph was _less_wide_ than a space, and the width of the box was computed as too small, but then the article is incorrect in that it claims the font’s line feed glyph was _wider_ than a space.

(and for those wondering why a browser needs to compute the width of that text twice: I wouldn’t know, but browser layout engines are complex beasts)

Re: The Safari bug that never was (2022)

#54
post #17

I like how they were too modest to post the developer's comment in the bug: > "Also, this is a fantastic bug report. I don't know if I've ever seen a bug report this detailed before." Little things like that restore faith in humanity.

People often forget that there are brilliant developers who don’t need to be 10x to produce extreme value to those around them.

Re: The Safari bug that never was (2022)

#56
Having worked on two major web browsers, I can tell you that they spend a surprisingly large proportion of their time measuring text. Drawing text is only half as much of the cycles spent. We got a significant speed boost at one point by reverse engineering an undocumented fast text measuring OS API that a rival browser was using.

Re: The Safari bug that never was (2022)

#57
From the fix: https://bugs.webkit.org/attachment.cgi?id=448463&action=pret...

> Reviewed by NOBODY (OOPS!).

If I was reviewing the code, I would have asked why Myles changed WidthIterator.cpp's call to charactersTreatedAsSpace.constructAndAppend from a separate parameter on each line to everything inline.

This change made the diff of this change harder to read, and will make the diff of any future parameter change harder to read also.

I also would have created an intermediary variable or a helper method for `character == tabCharacter ? width : font.spaceWidth()` - it's not clear at all here why this check needs to be there (without looking at the ChangeLog, which I shouldn't have to do to understand code), or why the old behaviour that used `width` instead of `font.spaceWidth()` ONLY applies to tabCharacter (So it should be encapsulate inside a method with a clear comment with the info from the ChangeLog)

Lastly, this diff doesn't seem to match the blog description:

> The font also has data about the newline character, including its width. This doesn’t really make sense – new lines don’t (or at least shouldn’t) take up any space, but the font doesn’t treat it differently to any other character. The creator of the font still has to include a width for the new line character in the font’s data. And in the font we use on GOV.UK, the new line character has a bigger width than a space character – which is apparently unusual.

This makes it sound like the FONT is wrong and the font width shouldn't be used for width calculation. Yet the change in the code introduces using the font's space width explicitly.

Ultimately the ChangeLog doesn't match the code. I trust the blog writer, the code author, and the description of the bug in the ChangeLog. What needed improvement here then is the code to imperatively match what is described in English.

Re: The Safari bug that never was (2022)

#58
post #53
post #50

Earlier quoted context omitted.

The way I understood it in my head (though I don’t know if the article actually says this) is that process that figured out the box size was probably ignoring the new line and just assuming it was the same width as a space. The process that actually laid out the text was using the specified width of the new line, so it came up with a longer width and had to break the line.

But the thing is: as the article (correctly) says: “In HTML, any extra whitespace between words is ignored. This means you can add extra spaces, and even new lines, between words without affecting how they are displayed in the browser” So, “ignoring the new line and just assuming it was the same width as a space” is correct behaviour. I now think what happened is this: - the width of the box to render the text in was…

> So, “ignoring the new line and just assuming it was the same width as a space” is correct behaviour.

That's not true?

If it's a newline following whitespace then it should be ignored; the width should be calculated as zero, not the width of a space.

On the other hand, if it's not following whitespace the width should be that of the newline character, again not the width of a space.

Or am I misunderstanding you?

Re: The Safari bug that never was (2022)

#59
post #33

Earlier quoted context omitted.

That isn’t surprising. Even if the work is being done publicly, it still needs to be tracked and project-managed internally by the team.

> Even if the work is being done publicly, it still needs to be tracked and project-managed internally by the team. bugs.webkit.org is literally a bug tracker. The only relevant difference between Radar and WebKit Bugzilla is private vs. public.

> The only relevant difference between Radar and WebKit Bugzilla is private vs. public.

No, this is not true. Radar is not just "a bug tracker" — it is a very powerful project management tool, custom-built over several decades for the way Apple works, with integrations into other internal tools and processes.

It should be obvious why Apple wants to track work being done on Webkit using the same tool it uses to track work being done on every other project at the company.

Re: The Safari bug that never was (2022)

#60

i think these are the same team that has the post about why html number input is bad? to think, such amazing work from government. at least in US we tend to think these are not the most highly skilled people

The US attitude to government is a self-fulfilling prophecy. You don't give a chance to succeed to those you expect to fail.
Post reply on HN