diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-11-09 14:35:09 +0000 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-11-09 14:35:09 +0000 |
commit | ef595aedfce66caf2e8560b3605d38e95872e1ca (patch) | |
tree | a39d7bb419db8598f06dae75d90306474a7cf1f7 /transform/absurl.go | |
parent | 90a902c843758bb0d4c6da5ace4b9a813ab3a10e (diff) |
Handle schema-less urls when apply absurl
Fixes #114
Diffstat (limited to 'transform/absurl.go')
-rw-r--r-- | transform/absurl.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/transform/absurl.go b/transform/absurl.go index 80716f1b7..8bdd36515 100644 --- a/transform/absurl.go +++ b/transform/absurl.go @@ -23,15 +23,22 @@ func AbsURL(absURL string) (trs []link, err error) { hrefsq = []byte(" href='" + base + "/") ) trs = append(trs, func(content []byte) []byte { - content = bytes.Replace(content, []byte(" src=\"/"), srcdq, -1) - content = bytes.Replace(content, []byte(" src='/"), srcsq, -1) - content = bytes.Replace(content, []byte(" href=\"/"), hrefdq, -1) - content = bytes.Replace(content, []byte(" href='/"), hrefsq, -1) + content = guardReplace(content, []byte(" src=\"//"), []byte(" src=\"/"), srcdq) + content = guardReplace(content, []byte(" src='//"), []byte(" src='/"), srcsq) + content = guardReplace(content, []byte(" href=\"//"), []byte(" href=\"/"), hrefdq) + content = guardReplace(content, []byte(" href='//"), []byte(" href='/"), hrefsq) return content }) return } +func guardReplace(content, guard, match, replace []byte) []byte { + if !bytes.Contains(content, guard) { + content = bytes.Replace(content, match, replace, -1) + } + return content +} + type elattr struct { tag, attr string } |