Skip to content

Fix URL encoding for product tags in OpenCart 3#14256

Merged
mhcwebdesign merged 1 commit intoopencart:3.0.x.xfrom
head-dunce:fix-url-encoding-tags
Dec 5, 2024
Merged

Fix URL encoding for product tags in OpenCart 3#14256
mhcwebdesign merged 1 commit intoopencart:3.0.x.xfrom
head-dunce:fix-url-encoding-tags

Conversation

@head-dunce
Copy link
Copy Markdown

Issue

Product tags with special characters (e.g., &, spaces) were not properly encoded, causing broken phrases

Fix

Updated the product controller to use rawurlencode() and html_entity_decode() to handle special characters and HTML entities correctly.

File Modified

  • upload/catalog/controller/product/product.php

Testing

Changed the URL generation for product tags to ensure proper handling of special characters, such as ampersands (&).
Used `rawurlencode()` with `html_entity_decode()` to address issues with HTML entity encoding and ensure full compatibility with URL encoding standards.
@mhcwebdesign mhcwebdesign merged commit e59e9bc into opencart:3.0.x.x Dec 5, 2024
@mhcwebdesign
Copy link
Copy Markdown
Contributor

Thanks for this bugfix.

@ADDCreative
Copy link
Copy Markdown
Contributor

This doesn't completely fix the issue. You need to also change the encoding on the breadcrumb links, etc.

$url .= '&tag=' . $this->request->get['tag'];

$url .= '&tag=' . $this->request->get['tag'];

$url .= '&tag=' . $this->request->get['tag'];

Maybe also use urlencode to be consistent with the links generated on the search page.

$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));

@head-dunce
Copy link
Copy Markdown
Author

Ah, yeah good catch on the breadcrumbs. I used rawurlencode instead of urlencode since it encodes spaces at %20 instead of + because %20 was how the spaces were in the url before the fix. I don't think it technically matters which way though since it's in the query.

@mhcwebdesign
Copy link
Copy Markdown
Contributor

@ADDCreative : You are right for these other links, e.g. breadcrumbs etc. Just updated and tested it, see #14257 . Was going for urlencode, as that's what is used in most cases in OpenCart. According to the W3C, both '+' or '%20' are valid for URL encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants