logo科技微讯

url-cheatsheet

作者:科技微讯
日期:2022-12-30
📝 笔记

url-cheatsheet 较为详细地介绍了如何使用 javascript 处理 url,包括以下内容:

  1. DO NOT: concat url and user input without escape
  2. DO NOT: concat parameter and user input without escape
  3. Base URL + Path
  4. Get parameter from URL
  5. Get multiple parameters as array from URL
  6. Add parameters to URL
  7. Update parameter of URL
  8. Remove parameter from URL
  9. Filter parameters
  10. Check URL is Absolute-URL
  11. Check URL is HTTP

第 2 条,不要把未经过 escape 的字符串作为参数拼接到 url 中,拼接参数使用第 6 条可能是更好的做法,因为 url.search = new URLSearchParams({ q }) 中的 new URLSearchParams() 会自动对字符串进行 escape。

donation赞赏
thumbsup0
thumbsdown0
暂无评论