Thanks to visit codestin.com
Credit goes to github.com

Skip to content

代码中出现 "a.com",这是为了做什么吗 #4736

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

Closed
biubiukam opened this issue May 6, 2025 · 1 comment
Closed

代码中出现 "a.com",这是为了做什么吗 #4736

biubiukam opened this issue May 6, 2025 · 1 comment

Comments

@biubiukam
Copy link

const { pathname, protocol } = new URL(url, 'http://a.com')
if (
// skip internal anchor links
!url.startsWith('#') &&
// skip mail/custom protocol links
protocol.startsWith('http') &&
// skip links to files (other than html/md)
treatAsHtml(pathname)
) {
normalizeHref(hrefAttr, env)
} else if (url.startsWith('#')) {
hrefAttr[1] = decodeURI(normalizeHash(hrefAttr[1]))
}
// append base to internal (non-relative) urls
if (hrefAttr[1].startsWith('/')) {
hrefAttr[1] = `${base}${hrefAttr[1]}`.replace(/\/+/g, '/')
}

这个 "a.com" 是为了做什么吗,遇到一个CDN代理的需求,就打算全局将所有js文件中的协议、域名全部通过正则替换后更改,但是遇到这个 "a.com",感觉有点奇怪

@brc-dd
Copy link
Member

brc-dd commented May 6, 2025

URL parsing needs a base and http://a.com is one of the smallest safe base to use.

@brc-dd brc-dd closed this as completed May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants