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:
kyle
2018-10-16 18:51:29 -05:00
committed by GitHub
parent 94b1355700
commit 3c3b7e0bf1
7 changed files with 231 additions and 12 deletions

View File

@@ -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)
}
}