To reproduce:
- Create a paste named paste.js.
- Set the language to "C" and rename it to paste.rainbow, simultaneously.
- Set the language to autodetect.
Expected result:
- Paste highlights as rainbow.
Actual result:
- Paste still highlighted as JS.
To "fix" this, run bin/cache purge --purge-general. This will drop the cache and highlight the paste as Rainbow.
This is because PhabricatorPasteQuery's methods getContentCacheKey() and getSnippetCacheKey() don't include the name as part of the cache key. They should, because it's relevant to which highlighter is used if the language is set to autodetect.
Because names may be very long, this might create a cachekey length issue with long pastes. If it does, you can use PhabricatorHash::digestForIndex(...) to hash the name to 12 characters.
Also, when you set a Paste to autodetect the transaction that appears in the transaction log is rendered oddly:
hector updated the paste's language from rainbow to .
Instead, it should read something more like this:
hector updated the paste's language from rainbow to autodetect.
You can add this case to PhabricatorPasteLanguageTransaction. Fix both getTitle() (on the Paste) and getTitleForFeed() (on /feed/).