• Hello everyone,

    My team and I have encountered a problem with the tag autocomplete field when the tag we are looking for contains apostrophes.

    For example, I previously added two new tags marvel's comics and marvel snap and these tags are present in the tag list.

    Now I’m in a new message and I want to add the tag marvel's comics. The autocomplete results appear up to the apostrophe for “marvel’s”, but after the apostrophe I don’t see any results.

    The adjacent problem is that a lot of duplicate tags are created, making it difficult to find your way around.

    If I look at the ajax call, I see the following url parameter: search=marvel%27s%20comics. The same call with search=marvel's%20comics works fine, so I think the problem comes from the encoding used for the Ajax call.

    Is anyone able to reproduce this problem?
    Do you have any idea how I can solve it?

    Thank you very much.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Encoding apostrophes in URL query string values is necessary for the URL to be 100% standards compliant. Failure to properly encode can lead to vulnerabilities. It’s thus necessary for the receiving code to decode any incoming data.

    I’m unable to replicate the behavior you’ve described on my test site. I think what’s happening is the apostrophe is seen by code as a quote so it thinks there’s not more string content after it. It’s probably just side effect of not properly decoding the %27. If properly decoded, all should work as expected.

    Since I cannot replicate the behavior, I suspect your theme or a plugin is interfering with the process. Narrow down the source by deactivating all plugins and switching to a default Twenty* theme. Auto-fill should now work as expected. Restore your theme and plugins, one at a time, testing after each. When the problem recurs, the last activated module would be the cause. Take up this issue through that module’s dedicated support channel.

    Note that there is some upper limit to the number of auto-fill suggestions. It can happen that the initial suggestions do not contain all possible matches. Naturally as you type more, the matched count decreases and the tag being sought will eventually show up.

    Thread Starter noisegratte

    (@noisegratte)

    Hi @bcworkz ,

    By the way, I forgot to say that I tested this problem with a new WP installation (official Docker image), with the Twenty Twenty Three template and without complementary plugin installed, with French set as default language.

    As you say, it’s “probably a side effect of bad %27 decoding” and that’s what I noticed too. The JS call seems not to decode the apostrophe correctly before making the ajax call and therefore returns no result. As I said earlier, if I simulate the call with the correct encoding, the expected results are indeed returned.

    You can see here https://ibb.co/P9KcWzz the wp_terms stored in my database with the encoding defined. Perhaps you can reproduce the problem I’m having with this data?

    Thanks a lot

    Moderator bcworkz

    (@bcworkz)

    The encodings you show are HTML entities. That’s odd if your site is UTF-8 encoded. The raw data should be the actual apostrophe character as in marvel's comics. Out of curiosity, I altered my DB data to use an HTML entity like yours and it didn’t impact the tag auto-complete functionality.

    While entity encoding is odd, it doesn’t impact the auto-complete. I cannot replicate your issue on my site. If you have a fresh install with no plugins and 2023 theme, we have identical sites code-wise. We now have identical marvel’s comics tags as well. Thus differing behaviors would be because of something external to WP. What that might be I cannot imagine.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Autocomplete issue with tags containing apostrophes’ is closed to new replies.