bug(deeplinking): escaping breaks whitespaces & underscored tags/ids (via #4953)
* add tests for operation lacking an operationId * add deep linking tests for tags/operationIds with underscores * migrate from `_` to `%20` for deeplink hash whitespace escaping * add backwards compatibility for `_` whitespace escaping * update util unit tests
This commit is contained in:
@@ -73,18 +73,35 @@ export const parseDeepLinkHash = (rawHash) => ({ layoutActions, layoutSelectors,
|
||||
hash = hash.slice(1)
|
||||
}
|
||||
|
||||
const hashArray = hash.split("/").map(val => (val || "").replace(/_/g, " "))
|
||||
const hashArray = hash.split("/").map(val => (val || "").replace(/%20/g, " "))
|
||||
|
||||
const isShownKey = layoutSelectors.isShownKeyFromUrlHashArray(hashArray)
|
||||
|
||||
const [type, tagId] = isShownKey
|
||||
const [type, tagId, maybeOperationId] = isShownKey
|
||||
|
||||
if(type === "operations") {
|
||||
// we're going to show an operation, so we need to expand the tag as well
|
||||
layoutActions.show(layoutSelectors.isShownKeyFromUrlHashArray([tagId]))
|
||||
const tagIsShownKey = layoutSelectors.isShownKeyFromUrlHashArray([tagId])
|
||||
layoutActions.show(tagIsShownKey)
|
||||
|
||||
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
||||
// TODO: remove this in v4.0, it is deprecated
|
||||
if(tagId.indexOf("_") > -1) {
|
||||
console.warn("Warning: escaping deep link whitespace with `_` will be unsupported in v4.0, use `%20` instead.")
|
||||
layoutActions.show(tagIsShownKey.map(val => val.replace(/_/g, " ")), true)
|
||||
}
|
||||
}
|
||||
|
||||
layoutActions.show(isShownKey, true) // TODO: 'show' operation tag
|
||||
layoutActions.show(isShownKey, true)
|
||||
|
||||
// If an `_` is present, trigger the legacy escaping behavior to be safe
|
||||
// TODO: remove this in v4.0, it is deprecated
|
||||
if (tagId.indexOf("_") > -1 || maybeOperationId.indexOf("_") > -1) {
|
||||
console.warn("Warning: escaping deep link whitespace with `_` will be unsupported in v4.0, use `%20` instead.")
|
||||
layoutActions.show(isShownKey.map(val => val.replace(/_/g, " ")), true)
|
||||
}
|
||||
|
||||
// Scroll to the newly expanded entity
|
||||
layoutActions.scrollTo(isShownKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user