Update include_relative tests
This verifies you can’t go “up” in the include
This commit is contained in:
parent
41a6037a11
commit
0675f2a423
|
@ -13,8 +13,6 @@ module Jekyll
|
||||||
|
|
||||||
class IncludeTag < Liquid::Tag
|
class IncludeTag < Liquid::Tag
|
||||||
|
|
||||||
SYNTAX_EXAMPLE = "{% include file.ext param='value' param2='value' %}"
|
|
||||||
|
|
||||||
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
VALID_SYNTAX = /([\w-]+)\s*=\s*(?:"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|([\w\.-]+))/
|
||||||
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
VARIABLE_SYNTAX = /(?<variable>[^{]*\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\}[^\s}]*)(?<params>.*)/
|
||||||
|
|
||||||
|
@ -30,6 +28,10 @@ module Jekyll
|
||||||
validate_params if @params
|
validate_params if @params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def syntax_example
|
||||||
|
"{% include file.ext param='value' param2='value' %}"
|
||||||
|
end
|
||||||
|
|
||||||
def parse_params(context)
|
def parse_params(context)
|
||||||
params = {}
|
params = {}
|
||||||
markup = @params
|
markup = @params
|
||||||
|
@ -59,7 +61,7 @@ Invalid syntax for include tag. File contains invalid characters or sequences:
|
||||||
|
|
||||||
Valid syntax:
|
Valid syntax:
|
||||||
|
|
||||||
#{SYNTAX_EXAMPLE}
|
#{syntax_example}
|
||||||
|
|
||||||
eos
|
eos
|
||||||
end
|
end
|
||||||
|
@ -75,7 +77,7 @@ Invalid syntax for include tag:
|
||||||
|
|
||||||
Valid syntax:
|
Valid syntax:
|
||||||
|
|
||||||
#{SYNTAX_EXAMPLE}
|
#{syntax_example}
|
||||||
|
|
||||||
eos
|
eos
|
||||||
end
|
end
|
||||||
|
@ -154,6 +156,10 @@ eos
|
||||||
page_path = context.registers[:page].nil? ? includes_dir : File.dirname(context.registers[:page]["path"])
|
page_path = context.registers[:page].nil? ? includes_dir : File.dirname(context.registers[:page]["path"])
|
||||||
Jekyll.sanitized_path(context.registers[:site].source, page_path)
|
Jekyll.sanitized_path(context.registers[:site].source, page_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def syntax_example
|
||||||
|
"{% include_relative file.ext param='value' param2='value' %}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -568,6 +568,25 @@ CONTENT
|
||||||
assert_equal 'Included file \'./missing.html\' not found', exception.message
|
assert_equal 'Included file \'./missing.html\' not found', exception.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "include existing file above you" do
|
||||||
|
setup do
|
||||||
|
@content = <<CONTENT
|
||||||
|
---
|
||||||
|
title: higher file
|
||||||
|
---
|
||||||
|
|
||||||
|
{% include_relative ../README.markdown %}
|
||||||
|
CONTENT
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise error relative to source directory" do
|
||||||
|
exception = assert_raise ArgumentError do
|
||||||
|
create_post(@content, {'permalink' => 'pretty', 'source' => source_dir, 'destination' => dest_dir, 'read_posts' => true})
|
||||||
|
end
|
||||||
|
assert_equal "Invalid syntax for include tag. File contains invalid characters or sequences:\n\n ../README.markdown\n\nValid syntax:\n\n {% include_relative file.ext param='value' param2='value' %}\n\n", exception.message
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with symlink'd include" do
|
context "with symlink'd include" do
|
||||||
|
|
Loading…
Reference in New Issue