diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2018-10-14 23:53:37 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-14 23:53:37 -0600 |
| commit | 951a4eba67504a4ab0281eeabe9af2fe72f3da8a (patch) | |
| tree | 9b79d7d01803321f28ee8a7cdb935af37eb50090 | |
| parent | 1f30732d436660fa41e5a114674e4a844dace5a1 (diff) | |
resolves #2914 interpret open line range as infinite (PR #2917)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 6 | ||||
| -rw-r--r-- | test/reader_test.rb | 17 |
3 files changed, 21 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 01d26075..bc8dea9b 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -58,6 +58,7 @@ Fixes:: Improvements:: + * interpret open line range as infinite (#2914) * rename number property on AbstractBlock to numeral, but keep number as deprecated alias * use CSS class instead of hard-coded inline float style on tables and images (#2753) * use CSS class instead of hard-coded inline text-align style on block images (#2753) diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index e0e40299..55d39eb1 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -875,9 +875,9 @@ class PreprocessorReader < Reader if parsed_attrs.key? 'lines' inc_linenos = [] (split_delimited_value parsed_attrs['lines']).each do |linedef| - if linedef.include?('..') - from, to = linedef.split('..', 2).map {|it| it.to_i } - inc_linenos += to < 0 ? [from, 1.0/0.0] : ::Range.new(from, to).to_a + if linedef.include? '..' + from, to = linedef.split '..', 2 + inc_linenos += (to.empty? || (to = to.to_i) < 0) ? [from.to_i, 1.0/0.0] : ::Range.new(from.to_i, to).to_a else inc_linenos << linedef.to_i end diff --git a/test/reader_test.rb b/test/reader_test.rb index 226f3ea9..0c71228c 100644 --- a/test/reader_test.rb +++ b/test/reader_test.rb @@ -932,6 +932,23 @@ include::fixtures/include-file.asciidoc[lines="1, 3..4 , 6 .. -1"] assert_match(/last line of included content/, output) end + test 'include directive supports implicit endless range' do + input = <<-EOS +include::fixtures/include-file.asciidoc[lines=6..] + EOS + + output = convert_string_to_embedded input, :safe => :safe, :base_dir => DIRNAME + refute_match(/first line/, output) + refute_match(/second line/, output) + refute_match(/third line/, output) + refute_match(/fourth line/, output) + refute_match(/fifth line/, output) + assert_match(/sixth line/, output) + assert_match(/seventh line/, output) + assert_match(/eighth line/, output) + assert_match(/last line of included content/, output) + end + test 'include directive ignores empty lines attribute' do input = <<-EOS ++++ |
