// 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" "github.com/spf13/hugo/helpers" "github.com/stretchr/testify/assert" "path/filepath" "strings" "testing" ) const H5_JS_CONTENT_DOUBLE_QUOTE = "
content foobar. Follow up
" const H5_JS_CONTENT_SINGLE_QUOTE = "
content foobar. Follow up
" const H5_JS_CONTENT_ABS_URL = "
content foobar. Follow up
" const H5_JS_CONTENT_ABS_URL_SCHEMALESS = "
content foobar. Follow up
" const CORRECT_OUTPUT_SRC_HREF_SQ = "
content foobar. Follow up
" const H5_XML_CONTENT_ABS_URL = "<p><a href="/foobar">foobar</a></p> <p>A video: <iframe src='/foo'></iframe></p>" const CORRECT_OUTPUT_SRC_HREF_IN_XML = "<p><a href="http://base/foobar">foobar</a></p> <p>A video: <iframe src='http://base/foo'></iframe></p>" const H5_XML_CONTENT_GUARDED = "<p><a href="//foobar">foobar</a></p> <p>A video: <iframe src='//foo'></iframe></p>" // additional sanity tests for replacements testing const REPLACE_1 = "No replacements." const REPLACE_2 = "ᚠᛇᚻ ᛒᛦᚦ ᚠᚱᚩᚠᚢᚱ\nᚠᛁᚱᚪ ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" const REPLACE_3 = `End of file: src="/` const REPLACE_4 = `End of file: srcset="/` const REPLACE_5 = `Srcsett with no closing quote: srcset="/img/small.jpg do be do be do.` // Issue: 816, schemaless links combined with others const REPLACE_SCHEMALESS_HTML = `Pre. src='//schemaless' src='/normal' Schemaless. normal. Post.` const REPLACE_SCHEMALESS_HTML_CORRECT = `Pre. src='//schemaless' src='http://base/normal' Schemaless. normal. Post.` const REPLACE_SCHEMALESS_XML = `Pre. src='//schemaless' src='/normal' Schemaless. normal. Post.` const REPLACE_SCHEMALESS_XML_CORRECT = `Pre. src='//schemaless' src='http://base/normal' Schemaless. normal. Post.` // srcset= const SRCSET_BASIC = `Pre. text` const SRCSET_BASIC_CORRECT = `Pre. text` const SRCSET_SINGLE_QUOTE = `Pre. text POST.` const SRCSET_SINGLE_QUOTE_CORRECT = `Pre. text POST.` const SRCSET_XML_BASIC = `Pre. "text"` const SRCSET_XML_BASIC_CORRECT = `Pre. "text"` const SRCSET_XML_SINGLE_QUOTE = `Pre. "text"` const SRCSET_XML_SINGLE_QUOTE_CORRECT = `Pre. "text"` const SRCSET_VARIATIONS = `Pre. Missing start quote: text src='/img/foo.jpg'> FOO. schemaless: schemaless2: text src='http://base/img/foo.jpg'> FOO. schemaless: schemaless2: