-
Notifications
You must be signed in to change notification settings - Fork 4
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
[CSL-3108] Trim space adjustments #183
Changes from 4 commits
9b78a88
f25457a
c741aba
73cc2a8
15efffa
7ef6545
487acb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,11 @@ function createAutocompleteUrl(query, parameters, userParameters, options) { | |
queryParams.i = clientId; | ||
queryParams.s = sessionId; | ||
|
||
// Validate query (term) is provided | ||
if (!query || typeof query !== 'string') { | ||
// Trim non breaking spaces from query | ||
const queryTrimmed = helpers.trimNonBreakingSpaces(query); | ||
|
||
// Validate query (term) is provided and consists of more than non-breaking spaces | ||
if (!queryTrimmed || typeof queryTrimmed !== 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added to ensure we don't dispatch requests consisting of solely non-breaking spaces (ex: |
||
throw new Error('query is a required parameter of type string'); | ||
} | ||
|
||
|
@@ -112,7 +115,8 @@ function createAutocompleteUrl(query, parameters, userParameters, options) { | |
const queryString = qs.stringify(queryParams, { indices: false }); | ||
const cleanedQuery = query.replace(/^\//, '|'); // For compatibility with backend API | ||
|
||
return `${serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(cleanedQuery))}?${queryString}`; | ||
// Note: it is intentional that query is dispatched without being trimmed (`queryTrimmed`) | ||
return `${serviceUrl}/autocomplete/${helpers.encodeURIComponentRFC3986(cleanedQuery)}?${queryString}`; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,11 @@ function createSearchUrl(query, parameters, userParameters, options, isVoiceSear | |
queryParams.i = clientId; | ||
queryParams.s = sessionId; | ||
|
||
// Validate query (term) is provided | ||
if (!query || typeof query !== 'string') { | ||
// Trim non breaking spaces from query | ||
const queryTrimmed = helpers.trimNonBreakingSpaces(query); | ||
|
||
// Validate query (term) is provided and consists of more than non-breaking spaces | ||
if (!queryTrimmed || typeof queryTrimmed !== 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was added to ensure we don't dispatch requests consisting of solely non-breaking spaces (ex: |
||
throw new Error('query is a required parameter of type string'); | ||
} | ||
|
||
|
@@ -145,7 +148,7 @@ function createSearchUrl(query, parameters, userParameters, options, isVoiceSear | |
|
||
const searchUrl = isVoiceSearch ? 'search/natural_language' : 'search'; | ||
|
||
return `${serviceUrl}/${searchUrl}/${helpers.encodeURIComponentRFC3986(helpers.trimNonBreakingSpaces(query))}?${queryString}`; | ||
return `${serviceUrl}/${searchUrl}/${helpers.encodeURIComponentRFC3986(queryTrimmed)}?${queryString}`; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore this, but should we just import the specific function here so we don't have helpers and utilsHelpers? Haha
i.e.
const { trimNonBreakingSpaces } = require('../../../src/utils/helpers');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great callout - this is going to go away anyway. We should not be trimming on search either