Fixing a Chrome dictionary issue

A technical description of fixing a browser bug and contributing to Chrome’s codebase

The problem

Image for post
Image for post

I found out it was originally filed as a bug in Chromium in December 2012. Some friendly people also linked to the matching bug upstream in the wordlist repository, and provided enough context and encouragement.

This is how I approached fixing that bug.

Installing and compiling Chromium

I compiled Chromium on Windows as per official instructions (and a bit here). Note: I needed around 40–50GB for code alone, not to mention Visual Studio.

I verified that my Chromium runs by running out\Debug\chrome.exe in the command line. (You know you’re on Windows when you use backslashes instead of / in your paths.)

Also, as a one time operation, I built the convert_dict tool by going to the same directory I built Chromium, and entering ninja -C out\Debug convert_dict

First intermediate goal

The first goal was trying to add a nonexistent word to dictionary to see if it’s picked up properly. My choice was “typotypography,” which doesn’t exist:

Image for post
Image for post

I closed Chromium.

I went to src\third_party\hunspell_dictionaries, and opened en_US.dic in a text editor (Sublime Text for Windows).

I added typotypography in the right place:

Image for post
Image for post

I went to command line, to src\third_party_hunspell_dictionaries directory. I then ran the previously compiled convert_dict tool to compile the dictionary.

E:\src\third_party\hunspell_dictionaries>\src\out\Debug\convert_dict.exe en_US
Reading en_US.aff ...
Reading en_US.dic ...
Reading en_US.dic_delta ...
Serializing...
Verifying...
Writing en_US.bdic ...

Lastly, I copied the generated dictionary to the right place:

E:\src>copy third_party\hunspell_dictionaries\en_US.bdic out\Debug\Dictionaries\en-US-4–0.bdic

Then I ran Chromium:

E:\src>out\debug\Chrome

And verified that the change worked:

Image for post
Image for post

Second intermediate goal

I went to en_US.aff file, and changed the header from:

SET ISO8859-1
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
NOSUGGEST !

to:

SET ISO8859-1
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
NOSUGGEST !
ICONV 1
ICONV : '

I followed all the dictionary compilation steps from above, and verified by relaunching Chromium and typing didn:t — it was no longer underlined in red.

Image for post
Image for post

Actual goal

SET ISO8859-1
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
NOSUGGEST !

To:

SET UTF8
TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ'
NOSUGGEST !
ICONV 1
ICONV ’ '

The change to UTF-8 would require converting the dictionary file to UTF-8 as well… except American English dictionary file was all ASCII, so it didn’t matter.

I followed the dictionary compilation rules as above, relaunched Chromium, and verified it worked:

Image for post
Image for post

Final steps

Then, in order to get my change into Chromium faster, I also patched Chromium directly.

I went into src\third_party\hunspell_dictionaries, and started a branch by invoking:

git checkout -b mwichary-typographical-quotes

Then, I followed usual git incantations:

git add en_US.affgit commit -m "Smart/typographical quotes for en-US."git cl upload

I changed the description and referred to the bug above. This is my patch (again, this was filed by someone else but that’s because of unusual circumstances).

Voilà! It took a few weeks for the change to make it from canary to beta to Chrome stable but, as of a few months ago, the bug is fixed, and smart quotes will not create any spellcheck issues — whether you’re using Medium or not.

It was easier than I thought, and it’s incredibly satisfying to have contributed a fix that every user of Chromium and Chrome will benefit from.

Thanks to Julie Russell, Paul Irish, Rouslan Solomakhin, Nils Enevoldsen, and Kevin Atkinson for their amazing help. This wouldn’t have happened without you!

Designer/typographer · Writing a book on the history of keyboards: https://aresluna.org/shift-happens

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store