Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not allow tricky id used as path; fix #1393 #1565

Merged
merged 2 commits into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/review/book/index/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@ def initialize(id, number, caption = nil)
alias_method :content, :caption

def path
@path ||= @index.find_path(id)
if @path
return @path
end

if @id =~ /\s/
raise ReVIEW::SyntaxError, "invalid ID character for path: `#{@id}`"
end
@path = @index.find_path(@id)

@path
end
end
end
Expand Down
21 changes: 14 additions & 7 deletions test/test_htmlbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -665,25 +665,32 @@ def @chapter.image(_id)
assert_equal expected, actual
end

def test_image_with_tricky_id
def test_image_with_tricky_id_kana
def @chapter.image(_id)
item = Book::Index::Item.new('123 あ_;', 1)
item.instance_eval { @path = './images/chap1-123 あ_;.png' }
item = Book::Index::Item.new('123あいう', 1)
item.instance_eval { @path = './images/123あいう.png' }
item
end

actual = compile_block("//image[123 あ_;][sample photo]{\n//}\n")
@chapter.instance_eval { @name = 'ch01' }
actual = compile_block("//image[123あいう][sample photo]{\n//}\nimg: @<img>{123あいう}\n")
expected = <<-EOS
<div id="id_123-_E3_81_82___3B" class="image">
<img src="images/chap1-123 あ_;.png" alt="sample photo" />
<div id="id_123_E3_81_82_E3_81_84_E3_81_86" class="image">
<img src="images/123あいう.png" alt="sample photo" />
<p class="caption">
図1.1: sample photo
</p>
</div>
<p>img: <span class="imgref"><a href="./ch01.html#id_123_E3_81_82_E3_81_84_E3_81_86">図1.1</a></span></p>
EOS
assert_equal expected, actual
end

def test_image_with_tricky_id_space
assert_raise(ReVIEW::SyntaxError) do
_result = compile_block("//image[123 abc][sample photo]{\n//}\n")
end
end

def test_indepimage
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1)
Expand Down