Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double escape search result text #169

Open
othmantitee opened this issue Nov 29, 2023 · 1 comment
Open

Double escape search result text #169

othmantitee opened this issue Nov 29, 2023 · 1 comment

Comments

@othmantitee
Copy link

Summary
Special characters in the storefront autocomplete search result get escaped twice: once in the BE side, and once in the FE side.

Steps to reproduce

  1. Edit 0RT28 product name to "220 Lumen Rechargeable & Headlamp"
  2. Search for the product in the storefront.

Actual Result
Product name in search result shows as : 220 Lumen Rechargeable & Headlamp

Expected Result
Product name should show as : 220 Lumen Rechargeable & Headlamp

Details about your environment

  • OroCommerce version: 5.1.3
  • PHP version: 8.2.13
  • Database (MySQL, PostgreSQL) version: PostgreSQL 15.5 (Ubuntu 15.5-1.pgdg22.04+1)

Additional information
image

@othmantitee
Copy link
Author

It seems that Oro escape special characters in the autocomplete search result twice:

  1. At the backend side (PHP - HTML Sanitizer):

    protected function sanitize(array $data, $key = null): array
    {
    $userDefinedFields = ['sku', 'name', 'image', 'inventory_status', 'inventory_status_label'];
    if ($key && isset($data[$key])) {
    $data = $data[$key];
    }
    array_walk_recursive($data, function (&$value, $key) use ($userDefinedFields) {
    if (in_array($key, $userDefinedFields, false)) {
    $value = $this->htmlTagExtension->htmlSanitize($value);
    }
    });
    return $data;
    }

  2. At the frontend side (JS- Escaping) while rendering the search result in the autocomplete search component:

    return _.escape(value).replace(reg, highlightPattern);
    } else {
    return _.escape(value);
    }

Product Name: 220 Lumen Rechargeable & Headlamp
After Santize it: 220 Lumen Rechargeable & Headlamp
After Escaping it: 220 Lumen Rechargeable & Headlamp
After rendering it on Browser: 220 Lumen Rechargeable & Headlamp

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

No branches or pull requests

1 participant