闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
778 B

  1. import Link from 'http-link-header';
  2. import querystring from 'querystring';
  3. Link.parseAttrs = (link, parts) => {
  4. let match = null
  5. let attr = ''
  6. let value = ''
  7. let attrs = ''
  8. let uriAttrs = /<(.*)>;\s*(.*)/gi.exec(parts)
  9. if(uriAttrs) {
  10. attrs = uriAttrs[2]
  11. link = Link.parseParams(link, uriAttrs[1])
  12. }
  13. while(match = Link.attrPattern.exec(attrs)) { // eslint-disable-line no-cond-assign
  14. attr = match[1].toLowerCase()
  15. value = match[4] || match[3] || match[2]
  16. if( /\*$/.test(attr)) {
  17. Link.setAttr(link, attr, Link.parseExtendedValue(value))
  18. } else if(/%/.test(value)) {
  19. Link.setAttr(link, attr, querystring.decode(value))
  20. } else {
  21. Link.setAttr(link, attr, value)
  22. }
  23. }
  24. return link
  25. };
  26. export default Link;