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

Escape angle brackets in highlightField #1012

Merged
merged 9 commits into from
Nov 29, 2021
Merged

Escape angle brackets in highlightField #1012

merged 9 commits into from
Nov 29, 2021

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Nov 24, 2021

  • perform full HTML escape on the constructed highlighted text (will transform ", ', &, <, and >)
  • substr is deprecated, replaced with substring

J=SLAP-1703
TEST=manual & auto

update bryan's entity description to include script tags, search for 'where is joe exotic' and see that the script tags appear. (without the replacement, they do not appear)
see added jest tests passed

- replace all '<' and '>' in the plain text with '&lt;' and '&gt;' before providing highlight to the snippets

J=SLAP-1703
TEST=manual

update bryan's entity description to include script tags, search for 'where is joe exotic' and see that the script tags appear. (without the replacement, they do not appear)
@coveralls
Copy link

coveralls commented Nov 24, 2021

Coverage Status

Coverage increased (+0.03%) to 8.844% when pulling 85e61ab on dev/escape-brackets into 1322a6e on develop.

@yen-tt yen-tt added the WIP label Nov 29, 2021
@yen-tt yen-tt removed the WIP label Nov 29, 2021
static/js/formatters-internal.js Outdated Show resolved Hide resolved
static/js/formatters-internal.js Outdated Show resolved Hide resolved
@@ -540,20 +541,20 @@ export function priceRange(defaultPriceRange, countryCode) {
* highlight.
*/
export function highlightField(fieldValue, matchedSubstrings = []) {
let highlightedString = fieldValue;
let highlightedString = '';

// We must first sort the matchedSubstrings by decreasing offset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is out of date now that we are sorting by ascending offset

Copy link
Contributor

@oshi97 oshi97 Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we get some unit tests as well? specifically for cases with multiple highlighted substrings, since those are a little tricky, as well as the actual escaping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, just added!

@yen-tt yen-tt requested a review from oshi97 November 29, 2021 18:10
@yen-tt yen-tt merged commit ab4dfe8 into develop Nov 29, 2021
@yen-tt yen-tt deleted the dev/escape-brackets branch November 29, 2021 18:54
@tmeyer2115 tmeyer2115 mentioned this pull request Dec 14, 2021
tmeyer2115 added a commit that referenced this pull request Dec 14, 2021
### Features
- Consumer Authentication support was added for the Sandbox environment. (#996)
- The existing `image` formatter was updated to support photos sent from the Streams API. (#998)
- Support for Direct Answers on Vertical was added to the `vertical-standard` template. It is commented out by default. (#994)

### Changes
- To better support Consumer Authentication, the `AnswersExperience.init()` method can be called on `Document` load. (#995)
- The default `universalLimit` for all Vertical page configs was updated to 4. (#1010, #1021)

### Bugfixes
- Ensured that in all page templates, the `SpellCheck` appears above the `ResultsCount`. (#1011, #1017)
- In the `highlightedField` formatter, any HTML tag that appears in the text, that is not `<mark>` or `</mark>`, is now escaped. (#1012)
- Font pre-loads on Multi-lang sites now work correctly. (#1018)
- A new CSS variable was added: `--yxt-filter-options-option-label-line-height`. This variable, when kept in proper proportion to `--yxt-filters-and-sorts-font-size`, will ensure the scroll bar does not erroneously appear for filter options. (#1015, #1019)
@tmeyer2115 tmeyer2115 mentioned this pull request Jan 11, 2022
tmeyer2115 added a commit that referenced this pull request Jan 11, 2022
### Features
- Consumer Authentication support was added for the Sandbox environment. (#996)
- The existing `image` formatter was updated to support photos sent from the Streams API. (#998)
- Support for Direct Answers on Vertical was added to the `vertical-standard` template. It is commented out by default. (#994)

### Changes
- To better support Consumer Authentication, the `AnswersExperience.init()` method can be called on `Document` load. (#995)
- The default `universalLimit` for all Vertical page configs was updated to 4. (#1010, #1021)

### Bugfixes
- Ensured that in all page templates, the `SpellCheck` appears above the `ResultsCount`. (#1011, #1017)
- In the `highlightedField` formatter, any HTML tag that appears in the text, that is not `<mark>` or `</mark>`, is now escaped. (#1012)
- Font pre-loads on Multi-lang sites now work correctly. (#1018)
- A new CSS variable was added: `--yxt-filter-options-option-label-line-height`. This variable, when kept in proper proportion to `--yxt-filters-and-sorts-font-size`, will ensure the scroll bar does not erroneously appear for filter options. (#1015, #1019)
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.

5 participants