The pound sign that was seven characters long
The page writes £ as a seven-character code so browsers render it. Structured data is not a browser, so the same text has to be decoded before it goes in.
The pages on this site are written with a habit that dates from before every browser could be trusted with a pound sign: the character is spelled out as a seven-character code, an ampersand, the word pound, a semicolon. The browser turns it back into the single character on the way to the screen. Curly quotes, apostrophes, dashes and the ellipsis are all written the same way. A reader never sees the codes. A test that reads the page as text sees nothing else.
Yesterday we started generating question-and-answer blocks for the comparison pages, and the same generated sentence has to go to two places. One is the page body, where the browser will decode it. The other is a block of structured data in the page’s head, which is not markup. It is a small document in its own notation, read by a crawler, and a crawler reading that notation does not decode markup codes inside it, because they are not supposed to be there. Put the seven-character pound sign into the structured block and the rich result, if one is ever shown, prints the seven characters.
So the generator decodes before it writes the block. There is a short table of the codes the site actually uses, the pound, the euro, the two dashes, four quotation marks, the ellipsis and the non-breaking space, plus the numeric form, and the sentence passes through it once on its way into the head. The same sentence goes into the body untouched. Two outputs from one source, in the two encodings the two readers expect.
That created a problem for the test, which is where the real lesson is. The test’s job is to prove that every answer in the structured block is also given in the page’s visible text. It reads the built page, takes the body, and asks whether the answer is a substring of it. With the pound sign decoded on one side and encoded on the other, the answer is never a substring, and the test would have failed on every page while reporting that the block said things the page did not. A comparison run against one encoding when the wire carries another: we have a number for that shape, because we have made the mistake before, in a different place.
The test now decodes the body with the same table before comparing, so both sides are characters. And it checks the other direction too: no answer in the block may contain an ampersand-word-semicolon sequence at all. If the decode step is ever removed, or a new code is used that the table does not know, the block carries the code into a crawler’s reading and the test fails by name rather than passing by accident.
None of this is visible on the page. The reader sees a pound sign in both places and nothing else. It matters only in the gap between what a browser does with a page and what a machine does with a page, and that gap is where most of the quiet faults on a website live.