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
改进 getSearch
函数实现
#7089
Merged
Merged
改进 getSearch
函数实现
#7089
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
兼容 key 为空字符串与 value 为空字符串的 URL search params
我回滚了, |
哎呀, 下面这个应该可以兼容😂 export const getSearch: (key: string, link?: string) => string | null = (key: string, link = window.location.search) => {
// REF https://developer.mozilla.org/zh-CN/docs/Web/API/URLSearchParams
const urlSearchParams = new URLSearchParams(link.substring(link.indexOf('?')));
return urlSearchParams.get(key);
}; |
可以继续 PR,最后如果是 null 的话就 return "", 这样其他地方就不用再改了。 😊 |
👌
这里返回 |
Zuoqiu-Yingyi
added a commit
to Zuoqiu-Yingyi/siyuan
that referenced
this pull request
Jan 16, 2023
兼容 `getSearch("page", "assets/第13章 编程陷阱-20220524015630-wd53jod.pdf?page=12")` REF: siyuan-note#7089
Vanessa219
pushed a commit
that referenced
this pull request
Jan 19, 2023
* 🎨 改进 `getSearch` 方法 兼容 key 为空字符串与 value 为空字符串的 URL search params * 🎨 改进 `getSearch` 方法 * 🎨 style * 🎨 改进 `getSearch` 方法 兼容 `getSearch("page", "assets/第13章 编程陷阱-20220524015630-wd53jod.pdf?page=12")` REF: #7089 * 🎨 改进 `getSearch` 方法 * `getSearch` 返回值兼容 `null` 与 `""`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
兼容 key 为空字符串与 value 为空字符串的 URL search params
URL search params 中
key
与value
均可为空字符串, 且其中的字符可能会进行 URI 编码, 因此需要进行规范处理