Merge pull request #3170 from evazion/fix-note-normalize-links

Convert absolute links in notes to relative links (fix #1911)
This commit is contained in:
Albert Yi
2017-06-19 13:23:39 -07:00
committed by GitHub
5 changed files with 41 additions and 13 deletions

View File

@@ -73,7 +73,20 @@ module NoteSanitizer
at_rules: [],
protocols: [],
properties: ALLOWED_PROPERTIES,
}
},
:transformers => method(:relativize_links),
)
end
def self.relativize_links(node:, **env)
return unless node.name == "a" && node.attribute("href")
href = node.attribute("href")
url = Addressable::URI.parse(href.value).normalize
if url.authority.in?(Danbooru.config.hostnames)
url.site = nil
href.value = url.to_s
end
end
end