// Copyright 2015 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package transform import ( "bytes" "path/filepath" "strings" "testing" "github.com/gohugoio/hugo/helpers" "github.com/stretchr/testify/assert" ) const ( h5JsContentDoubleQuote = "
content foobar. Follow up
" h5JsContentSingleQuote = "
content foobar. Follow up
" h5JsContentAbsURL = "
content foobar. Follow up
" h5JsContentAbsURLSchemaless = "
content foobar. Follow up
" corectOutputSrcHrefSq = "
content foobar. Follow up
" h5XMLXontentAbsURL = "<p><a href="/foobar">foobar</a></p> <p>A video: <iframe src='/foo'></iframe></p>" correctOutputSrcHrefInXML = "<p><a href="http://base/foobar">foobar</a></p> <p>A video: <iframe src='http://base/foo'></iframe></p>" h5XMLContentGuarded = "<p><a href="//foobar">foobar</a></p> <p>A video: <iframe src='//foo'></iframe></p>" ) const ( // additional sanity tests for replacements testing replace1 = "No replacements." replace2 = "ᚠᛇᚻ ᛒᛦᚦ ᚠᚱᚩᚠᚢᚱ\nᚠᛁᚱᚪ ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" replace3 = `End of file: src="/` replace4 = `End of file: srcset="/` replace5 = `Srcsett with no closing quote: srcset="/img/small.jpg do be do be do.` // Issue: 816, schemaless links combined with others replaceSchemalessHTML = `Pre. src='//schemaless' src='/normal' Schemaless. normal. Post.` replaceSchemalessHTMLCorrect = `Pre. src='//schemaless' src='http://base/normal' Schemaless. normal. Post.` replaceSchemalessXML = `Pre. src='//schemaless' src='/normal' Schemaless. normal. Post.` replaceSchemalessXMLCorrect = `Pre. src='//schemaless' src='http://base/normal' Schemaless. normal. Post.` ) const ( // srcset= srcsetBasic = `Pre. text` srcsetBasicCorrect = `Pre. text` srcsetSingleQuote = `Pre. text POST.` srcsetSingleQuoteCorrect = `Pre. text POST.` srcsetXMLBasic = `Pre. "text"` srcsetXMLBasicCorrect = `Pre. "text"` srcsetXMLSingleQuote = `Pre. "text"` srcsetXMLSingleQuoteCorrect = `Pre. "text"` srcsetVariations = `Pre. Missing start quote: text src='/img/foo.jpg'> FOO. schemaless: schemaless2: text src='http://base/img/foo.jpg'> FOO. schemaless: schemaless2: