asciidoctor 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of asciidoctor might be problematic. Click here for more details.

Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +72 -5
  3. data/CONTRIBUTING.adoc +3 -3
  4. data/Gemfile +23 -0
  5. data/README-fr.adoc +416 -0
  6. data/README-jp.adoc +395 -0
  7. data/README-zh_CN.adoc +414 -0
  8. data/README.adoc +134 -72
  9. data/asciidoctor.gemspec +49 -0
  10. data/data/locale/attributes.adoc +470 -0
  11. data/data/stylesheets/asciidoctor-default.css +6 -5
  12. data/lib/asciidoctor.rb +22 -19
  13. data/lib/asciidoctor/abstract_block.rb +20 -10
  14. data/lib/asciidoctor/abstract_node.rb +3 -14
  15. data/lib/asciidoctor/cli/invoker.rb +5 -4
  16. data/lib/asciidoctor/cli/options.rb +1 -1
  17. data/lib/asciidoctor/converter/docbook5.rb +1 -1
  18. data/lib/asciidoctor/converter/factory.rb +1 -5
  19. data/lib/asciidoctor/converter/html5.rb +36 -31
  20. data/lib/asciidoctor/converter/manpage.rb +14 -9
  21. data/lib/asciidoctor/converter/template.rb +8 -4
  22. data/lib/asciidoctor/core_ext.rb +7 -6
  23. data/lib/asciidoctor/core_ext/{string → 1.8.7/string}/chr.rb +1 -1
  24. data/lib/asciidoctor/core_ext/1.8.7/string/limit.rb +28 -0
  25. data/lib/asciidoctor/core_ext/{symbol → 1.8.7/symbol}/length.rb +1 -1
  26. data/lib/asciidoctor/core_ext/nil_or_empty.rb +23 -0
  27. data/lib/asciidoctor/core_ext/string/limit.rb +10 -0
  28. data/lib/asciidoctor/document.rb +33 -26
  29. data/lib/asciidoctor/extensions.rb +16 -16
  30. data/lib/asciidoctor/helpers.rb +1 -1
  31. data/lib/asciidoctor/list.rb +3 -0
  32. data/lib/asciidoctor/parser.rb +47 -43
  33. data/lib/asciidoctor/path_resolver.rb +3 -1
  34. data/lib/asciidoctor/reader.rb +15 -14
  35. data/lib/asciidoctor/section.rb +2 -2
  36. data/lib/asciidoctor/stylesheets.rb +2 -1
  37. data/lib/asciidoctor/substitutors.rb +44 -46
  38. data/lib/asciidoctor/table.rb +41 -38
  39. data/lib/asciidoctor/version.rb +1 -1
  40. data/man/asciidoctor.1 +11 -4
  41. data/man/asciidoctor.adoc +7 -1
  42. data/test/attributes_test.rb +52 -0
  43. data/test/blocks_test.rb +8 -8
  44. data/test/document_test.rb +13 -1
  45. data/test/extensions_test.rb +38 -0
  46. data/test/invoker_test.rb +15 -0
  47. data/test/lists_test.rb +78 -53
  48. data/test/manpage_test.rb +15 -0
  49. data/test/paths_test.rb +3 -0
  50. data/test/reader_test.rb +2 -2
  51. data/test/sections_test.rb +10 -0
  52. data/test/substitutions_test.rb +12 -6
  53. data/test/tables_test.rb +76 -2
  54. metadata +16 -45
  55. data/lib/asciidoctor/core_ext/object/nil_or_empty.rb +0 -23
  56. data/test/fixtures/asciidoc_index.txt +0 -521
  57. data/test/fixtures/basic-docinfo-footer.html +0 -6
  58. data/test/fixtures/basic-docinfo-footer.xml +0 -8
  59. data/test/fixtures/basic-docinfo.html +0 -1
  60. data/test/fixtures/basic-docinfo.xml +0 -4
  61. data/test/fixtures/basic.asciidoc +0 -5
  62. data/test/fixtures/chapter-a.adoc +0 -3
  63. data/test/fixtures/child-include.adoc +0 -5
  64. data/test/fixtures/circle.svg +0 -8
  65. data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +0 -6
  66. data/test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml +0 -6
  67. data/test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml +0 -1
  68. data/test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml +0 -3
  69. data/test/fixtures/custom-backends/haml/html5/block_sidebar.html.haml +0 -5
  70. data/test/fixtures/custom-backends/slim/docbook45/block_paragraph.xml.slim +0 -6
  71. data/test/fixtures/custom-backends/slim/html5/block_paragraph.html.slim +0 -3
  72. data/test/fixtures/custom-backends/slim/html5/block_sidebar.html.slim +0 -5
  73. data/test/fixtures/custom-docinfodir/basic-docinfo.html +0 -1
  74. data/test/fixtures/custom-docinfodir/docinfo.html +0 -1
  75. data/test/fixtures/docinfo-footer.html +0 -1
  76. data/test/fixtures/docinfo-footer.xml +0 -9
  77. data/test/fixtures/docinfo.html +0 -1
  78. data/test/fixtures/docinfo.xml +0 -3
  79. data/test/fixtures/dot.gif +0 -0
  80. data/test/fixtures/encoding.asciidoc +0 -13
  81. data/test/fixtures/grandchild-include.adoc +0 -3
  82. data/test/fixtures/hello-asciidoctor.pdf +0 -0
  83. data/test/fixtures/include-file.asciidoc +0 -24
  84. data/test/fixtures/include-file.xml +0 -5
  85. data/test/fixtures/master.adoc +0 -5
  86. data/test/fixtures/parent-include-restricted.adoc +0 -5
  87. data/test/fixtures/parent-include.adoc +0 -5
  88. data/test/fixtures/sample.asciidoc +0 -26
  89. data/test/fixtures/stylesheets/custom.css +0 -3
  90. data/test/fixtures/subs-docinfo.html +0 -2
  91. data/test/fixtures/subs.adoc +0 -7
  92. data/test/fixtures/tip.gif +0 -0
  93. data/test/test_helper.rb +0 -399
@@ -363,54 +363,50 @@ module Substitutors
363
363
  end
364
364
  alias :sub_specialcharacters :sub_specialchars
365
365
 
366
- # Public: Substitute quoted text (includes emphasis, strong, monospaced, etc)
367
- #
368
- # text - The String text to process
369
- #
370
- # returns The converted String text
371
- def sub_quotes(text)
372
- if ::RUBY_ENGINE_OPAL
373
- result = text
374
- QUOTE_SUBS[@document.compat_mode].each {|type, scope, pattern|
375
- result = result.gsub(pattern) { convert_quoted_text $~, type, scope }
376
- }
377
- else
366
+ if RUBY_ENGINE == 'opal'
367
+ def sub_quotes text
368
+ QUOTE_SUBS[@document.compat_mode].each do |type, scope, pattern|
369
+ text = text.gsub(pattern) { convert_quoted_text $~, type, scope }
370
+ end
371
+ text
372
+ end
373
+
374
+ def sub_replacements text
375
+ REPLACEMENTS.each do |pattern, replacement, restore|
376
+ text = text.gsub(pattern) { do_replacement $~, replacement, restore }
377
+ end
378
+ text
379
+ end
380
+ else
381
+ # Public: Substitute quoted text (includes emphasis, strong, monospaced, etc)
382
+ #
383
+ # text - The String text to process
384
+ #
385
+ # returns The converted String text
386
+ def sub_quotes text
378
387
  # NOTE interpolation is faster than String#dup
379
- result = %(#{text})
388
+ text = %(#{text})
380
389
  # NOTE using gsub! here as an MRI Ruby optimization
381
- QUOTE_SUBS[@document.compat_mode].each {|type, scope, pattern|
382
- result.gsub!(pattern) { convert_quoted_text $~, type, scope }
383
- }
390
+ QUOTE_SUBS[@document.compat_mode].each do |type, scope, pattern|
391
+ text.gsub!(pattern) { convert_quoted_text $~, type, scope }
392
+ end
393
+ text
384
394
  end
385
395
 
386
- result
387
- end
388
-
389
- # Public: Substitute replacement characters (e.g., copyright, trademark, etc)
390
- #
391
- # text - The String text to process
392
- #
393
- # returns The String text with the replacement characters substituted
394
- def sub_replacements(text)
395
- if ::RUBY_ENGINE_OPAL
396
- result = text
397
- REPLACEMENTS.each {|pattern, replacement, restore|
398
- result = result.gsub(pattern) {
399
- do_replacement $~, replacement, restore
400
- }
401
- }
402
- else
396
+ # Public: Substitute replacement characters (e.g., copyright, trademark, etc)
397
+ #
398
+ # text - The String text to process
399
+ #
400
+ # returns The String text with the replacement characters substituted
401
+ def sub_replacements text
403
402
  # NOTE interpolation is faster than String#dup
404
- result = %(#{text})
403
+ text = %(#{text})
405
404
  # NOTE Using gsub! as optimization
406
- REPLACEMENTS.each {|pattern, replacement, restore|
407
- result.gsub!(pattern) {
408
- do_replacement $~, replacement, restore
409
- }
410
- }
405
+ REPLACEMENTS.each do |pattern, replacement, restore|
406
+ text.gsub!(pattern) { do_replacement $~, replacement, restore }
407
+ end
408
+ text
411
409
  end
412
-
413
- result
414
410
  end
415
411
 
416
412
  # Internal: Substitute replacement text for matched location
@@ -642,6 +638,8 @@ module Substitutors
642
638
 
643
639
  target = m[1]
644
640
  attributes = if extension.config[:format] == :short
641
+ # TODO if content_model is :attributes, set target to nil and parse attributes
642
+ # maybe if content_model is :text, we should put content into text attribute
645
643
  {}
646
644
  else
647
645
  if extension.config[:content_model] == :attributes
@@ -1403,7 +1401,7 @@ module Substitutors
1403
1401
  unless (highlighter_loaded = defined? ::CodeRay) || @document.attributes['coderay-unavailable']
1404
1402
  if (Helpers.require_library 'coderay', true, :warn).nil?
1405
1403
  # prevent further attempts to load CodeRay
1406
- @document.set_attr 'coderay-unavailable', true
1404
+ @document.set_attr 'coderay-unavailable', ''
1407
1405
  else
1408
1406
  highlighter_loaded = true
1409
1407
  end
@@ -1412,7 +1410,7 @@ module Substitutors
1412
1410
  unless (highlighter_loaded = defined? ::Pygments) || @document.attributes['pygments-unavailable']
1413
1411
  if (Helpers.require_library 'pygments', 'pygments.rb', :warn).nil?
1414
1412
  # prevent further attempts to load Pygments
1415
- @document.set_attr 'pygments-unavailable', true
1413
+ @document.set_attr 'pygments-unavailable', ''
1416
1414
  else
1417
1415
  highlighter_loaded = true
1418
1416
  end
@@ -1460,7 +1458,7 @@ module Substitutors
1460
1458
  when 'coderay'
1461
1459
  if (linenums_mode = (attr? 'linenums') ? (@document.attributes['coderay-linenums-mode'] || :table).to_sym : nil)
1462
1460
  if attr? 'highlight', nil, false
1463
- highlight_lines = resolve_lines_to_highlight(attr 'highlight', nil, false)
1461
+ highlight_lines = resolve_highlight_lines(attr 'highlight', nil, false)
1464
1462
  end
1465
1463
  end
1466
1464
  result = ::CodeRay::Duo[attr('language', :text, false).to_sym, :html, {
@@ -1477,7 +1475,7 @@ module Substitutors
1477
1475
  opts[:style] = (@document.attributes['pygments-style'] || Stylesheets::DEFAULT_PYGMENTS_STYLE)
1478
1476
  end
1479
1477
  if attr? 'highlight', nil, false
1480
- unless (highlight_lines = resolve_lines_to_highlight(attr 'highlight', nil, false)).empty?
1478
+ unless (highlight_lines = resolve_highlight_lines(attr 'highlight', nil, false)).empty?
1481
1479
  opts[:hl_lines] = highlight_lines * ' '
1482
1480
  end
1483
1481
  end
@@ -1545,7 +1543,7 @@ module Substitutors
1545
1543
  end
1546
1544
 
1547
1545
  # e.g., highlight="1-5, !2, 10" or highlight=1-5;!2,10
1548
- def resolve_lines_to_highlight spec
1546
+ def resolve_highlight_lines spec
1549
1547
  lines = []
1550
1548
  spec.delete(' ').split(DataDelimiterRx).map do |entry|
1551
1549
  negate = false
@@ -77,9 +77,11 @@ class Table < AbstractBlock
77
77
 
78
78
  # smell like we need a utility method here
79
79
  # to resolve an integer width from potential bogus input
80
- pcwidth = attributes['width']
81
- pcwidth_intval = pcwidth.to_i.abs
82
- if pcwidth_intval == 0 && pcwidth != '0' || pcwidth_intval > 100
80
+ if (pcwidth = attributes['width'])
81
+ if (pcwidth_intval = pcwidth.to_i) > 100 || pcwidth_intval < 1
82
+ pcwidth_intval = 100 unless pcwidth_intval == 0 && (pcwidth == '0' || pcwidth == '0%')
83
+ end
84
+ else
83
85
  pcwidth_intval = 100
84
86
  end
85
87
  @attributes['tablepcwidth'] = pcwidth_intval
@@ -88,6 +90,8 @@ class Table < AbstractBlock
88
90
  @attributes['tableabswidth'] ||=
89
91
  ((@attributes['tablepcwidth'].to_f / 100) * @document.attributes['pagewidth']).round
90
92
  end
93
+
94
+ attributes['orientation'] = 'landscape' if attributes.key? 'rotate-option'
91
95
  end
92
96
 
93
97
  # Internal: Returns whether the current row being processed is
@@ -99,16 +103,16 @@ class Table < AbstractBlock
99
103
  # Internal: Creates the Column objects from the column spec
100
104
  #
101
105
  # returns nothing
102
- def create_columns col_specs
106
+ def create_columns colspecs
103
107
  cols = []
104
108
  width_base = 0
105
- col_specs.each do |col_spec|
106
- width_base += col_spec['width']
107
- cols << (Column.new self, cols.size, col_spec)
109
+ colspecs.each do |colspec|
110
+ width_base += colspec['width']
111
+ cols << (Column.new self, cols.size, colspec)
108
112
  end
109
113
  unless (@columns = cols).empty?
110
114
  @attributes['colcount'] = cols.size
111
- assign_col_widths(width_base == 0 ? nil : width_base)
115
+ assign_column_widths(width_base == 0 ? nil : width_base)
112
116
  end
113
117
  nil
114
118
  end
@@ -123,7 +127,7 @@ class Table < AbstractBlock
123
127
  # width_base - the total of the relative column values used for calculating percentage widths (default: nil)
124
128
  #
125
129
  # returns nothing
126
- def assign_col_widths width_base = nil
130
+ def assign_column_widths width_base = nil
127
131
  pf = 10.0 ** 4 # precision factor (multipler / divisor) for managing precision of calculated result
128
132
  total_width = col_pcwidth = 0
129
133
 
@@ -301,10 +305,10 @@ class Table::ParserContext
301
305
 
302
306
  # Public: Get the expected column count for a row
303
307
  #
304
- # col_count is the number of columns to pull into a row
308
+ # colcount is the number of columns to pull into a row
305
309
  # A value of -1 means we use the number of columns found
306
- # in the first line as the col_count
307
- attr_reader :col_count
310
+ # in the first line as the colcount
311
+ attr_reader :colcount
308
312
 
309
313
  # Public: The String buffer of the currently open cell
310
314
  attr_accessor :buffer
@@ -334,12 +338,12 @@ class Table::ParserContext
334
338
  attributes['separator'] || Table::DEFAULT_DELIMITERS[@format]
335
339
  end
336
340
  @delimiter_re = /#{Regexp.escape @delimiter}/
337
- @col_count = table.columns.empty? ? -1 : table.columns.size
341
+ @colcount = table.columns.empty? ? -1 : table.columns.size
338
342
  @buffer = ''
339
- @cell_specs = []
343
+ @cellspecs = []
340
344
  @cell_open = false
341
345
  @active_rowspans = [0]
342
- @col_visits = 0
346
+ @column_visits = 0
343
347
  @current_row = []
344
348
  @linenum = -1
345
349
  end
@@ -392,17 +396,17 @@ class Table::ParserContext
392
396
  # when the cell is being closed.
393
397
  #
394
398
  # returns The cell spec Hash captured from parsing the previous cell
395
- def take_cell_spec()
396
- @cell_specs.shift
399
+ def take_cellspec
400
+ @cellspecs.shift
397
401
  end
398
402
 
399
403
  # Public: Puts a cell spec onto the stack. Cell specs precede the delimiter, so a
400
404
  # stack is used to carry over the spec to the next cell.
401
405
  #
402
406
  # returns nothing
403
- def push_cell_spec(cell_spec = {})
407
+ def push_cellspec(cellspec = {})
404
408
  # this shouldn't be nil, but we check anyway
405
- @cell_specs << (cell_spec || {})
409
+ @cellspecs << (cellspec || {})
406
410
  nil
407
411
  end
408
412
 
@@ -443,8 +447,8 @@ class Table::ParserContext
443
447
  # by the next cell.
444
448
  #
445
449
  # returns nothing
446
- def close_open_cell(next_cell_spec = {})
447
- push_cell_spec next_cell_spec
450
+ def close_open_cell(next_cellspec = {})
451
+ push_cellspec next_cellspec
448
452
  close_cell(true) if cell_open?
449
453
  advance
450
454
  nil
@@ -459,17 +463,16 @@ class Table::ParserContext
459
463
  cell_text = @buffer.strip
460
464
  @buffer = ''
461
465
  if @format == 'psv'
462
- cell_spec = take_cell_spec
463
- if cell_spec
464
- repeat = cell_spec.fetch('repeatcol', 1)
465
- cell_spec.delete('repeatcol')
466
+ cellspec = take_cellspec
467
+ if cellspec
468
+ repeat = cellspec.delete('repeatcol') || 1
466
469
  else
467
470
  warn %(asciidoctor: ERROR: #{@last_cursor.line_info}: table missing leading separator, recovering automatically)
468
- cell_spec = {}
471
+ cellspec = {}
469
472
  repeat = 1
470
473
  end
471
474
  else
472
- cell_spec = nil
475
+ cellspec = nil
473
476
  repeat = 1
474
477
  if @format == 'csv'
475
478
  if !cell_text.empty? && cell_text.include?('"')
@@ -487,9 +490,9 @@ class Table::ParserContext
487
490
 
488
491
  1.upto(repeat) do |i|
489
492
  # TODO make column resolving an operation
490
- if @col_count == -1
493
+ if @colcount == -1
491
494
  @table.columns << (column = Table::Column.new(@table, @table.columns.size + i - 1))
492
- if cell_spec && (cell_spec.key? 'colspan') && (extra_cols = cell_spec['colspan'].to_i - 1) > 0
495
+ if cellspec && (cellspec.key? 'colspan') && (extra_cols = cellspec['colspan'].to_i - 1) > 0
493
496
  offset = @table.columns.size
494
497
  extra_cols.times do |j|
495
498
  @table.columns << Table::Column.new(@table, offset + j)
@@ -503,16 +506,16 @@ class Table::ParserContext
503
506
  end
504
507
  end
505
508
 
506
- cell = Table::Cell.new(column, cell_text, cell_spec, @last_cursor)
509
+ cell = Table::Cell.new(column, cell_text, cellspec, @last_cursor)
507
510
  @last_cursor = @reader.cursor
508
511
  unless !cell.rowspan || cell.rowspan == 1
509
512
  activate_rowspan(cell.rowspan, (cell.colspan || 1))
510
513
  end
511
- @col_visits += (cell.colspan || 1)
514
+ @column_visits += (cell.colspan || 1)
512
515
  @current_row << cell
513
516
  # don't close the row if we're on the first line and the column count has not been set explicitly
514
- # TODO perhaps the col_count/linenum logic should be in end_of_row? (or a should_end_row? method)
515
- close_row if end_of_row? && (@col_count != -1 || @linenum > 0 || (eol && i == repeat))
517
+ # TODO perhaps the colcount/linenum logic should be in end_of_row? (or a should_end_row? method)
518
+ close_row if end_of_row? && (@colcount != -1 || @linenum > 0 || (eol && i == repeat))
516
519
  end
517
520
  @cell_open = false
518
521
  nil
@@ -526,8 +529,8 @@ class Table::ParserContext
526
529
  @table.rows.body << @current_row
527
530
  # don't have to account for active rowspans here
528
531
  # since we know this is first row
529
- @col_count = @col_visits if @col_count == -1
530
- @col_visits = 0
532
+ @colcount = @column_visits if @colcount == -1
533
+ @column_visits = 0
531
534
  @current_row = []
532
535
  @active_rowspans.shift
533
536
  @active_rowspans[0] ||= 0
@@ -548,13 +551,13 @@ class Table::ParserContext
548
551
 
549
552
  # Public: Check whether we've met the number of effective columns for the current row.
550
553
  def end_of_row?
551
- @col_count == -1 || effective_col_visits == @col_count
554
+ @colcount == -1 || effective_column_visits == @colcount
552
555
  end
553
556
 
554
557
  # Public: Calculate the effective column visits, which consists of the number of
555
558
  # cells plus any active rowspans.
556
- def effective_col_visits
557
- @col_visits + @active_rowspans[0]
559
+ def effective_column_visits
560
+ @column_visits + @active_rowspans[0]
558
561
  end
559
562
 
560
563
  # Internal: Advance to the next line (which may come after the parser begins processing
@@ -1,3 +1,3 @@
1
1
  module Asciidoctor
2
- VERSION = '1.5.4'
2
+ VERSION = '1.5.5'
3
3
  end
@@ -1,13 +1,13 @@
1
1
  '\" t
2
2
  .\" Title: asciidoctor
3
3
  .\" Author: Dan Allen, Sarah White, Ryan Waldron
4
- .\" Generator: Asciidoctor 1.5.4
5
- .\" Date: 2016-01-05
4
+ .\" Generator: Asciidoctor 1.5.5
5
+ .\" Date: 2016-10-05
6
6
  .\" Manual: Asciidoctor Manual
7
- .\" Source: Asciidoctor 1.5.4
7
+ .\" Source: Asciidoctor 1.5.5
8
8
  .\" Language: English
9
9
  .\"
10
- .TH "ASCIIDOCTOR" "1" "2016-01-05" "Asciidoctor 1.5.4" "Asciidoctor Manual"
10
+ .TH "ASCIIDOCTOR" "1" "2016-10-05" "Asciidoctor 1.5.5" "Asciidoctor Manual"
11
11
  .ie \n(.g .ds Aq \(aq
12
12
  .el .ds Aq '
13
13
  .ss \n[.ss] 0
@@ -191,6 +191,13 @@ Print program version number.
191
191
  .sp
192
192
  \f[CR]\-v\fP can also be used if no other flags or arguments are present.
193
193
  .RE
194
+ .SH "ENVIRONMENT"
195
+ .sp
196
+ \fBAsciidoctor\fP honors the SOURCE_DATE_EPOCH environment variable.
197
+ If this variable is assigned an integer value, that value is used as the epoch of all input documents and as the local date and time.
198
+ See \c
199
+ .URL "https://reproducible\-builds.org/specs/source\-date\-epoch/" "" " "
200
+ for more information about this environment variable.
194
201
  .SH "EXIT STATUS"
195
202
  .sp
196
203
  \fB0\fP
@@ -2,7 +2,7 @@
2
2
  Dan Allen; Sarah White; Ryan Waldron
3
3
  :doctype: manpage
4
4
  :man manual: Asciidoctor Manual
5
- :man source: Asciidoctor 1.5.4
5
+ :man source: Asciidoctor 1.5.5
6
6
  :page-layout: base
7
7
 
8
8
  == NAME
@@ -144,6 +144,12 @@ Matching templates found in subsequent directories override ones previously disc
144
144
  +
145
145
  `-v` can also be used if no other flags or arguments are present.
146
146
 
147
+ == ENVIRONMENT
148
+
149
+ *Asciidoctor* honors the SOURCE_DATE_EPOCH environment variable.
150
+ If this variable is assigned an integer value, that value is used as the epoch of all input documents and as the local date and time.
151
+ See https://reproducible-builds.org/specs/source-date-epoch/ for more information about this environment variable.
152
+
147
153
  == EXIT STATUS
148
154
 
149
155
  *0*::
@@ -124,6 +124,58 @@ content
124
124
  assert result.include? '<em>big</em>foot'
125
125
  end
126
126
 
127
+ test 'should limit maximum size of attribute value if safe mode is SECURE' do
128
+ expected = 'a' * 4096
129
+ input = <<-EOS
130
+ :name: #{'a' * 5000}
131
+
132
+ {name}
133
+ EOS
134
+
135
+ result = render_embedded_string input, :doctype => :inline
136
+ assert_equal expected, result
137
+ assert_equal 4096, result.bytesize
138
+ end
139
+
140
+ test 'should handle multibyte characters when limiting attribute value size' do
141
+ expected = '日本'
142
+ input = <<-EOS
143
+ :name: 日本語
144
+
145
+ {name}
146
+ EOS
147
+
148
+ result = render_embedded_string input, :doctype => :inline, :attributes => { 'max-attribute-value-size' => 6 }
149
+ assert_equal expected, result
150
+ assert_equal 6, result.bytesize
151
+ end
152
+
153
+ test 'should not mangle multibyte characters when limiting attribute value size' do
154
+ expected = '日本'
155
+ input = <<-EOS
156
+ :name: 日本語
157
+
158
+ {name}
159
+ EOS
160
+
161
+ result = render_embedded_string input, :doctype => :inline, :attributes => { 'max-attribute-value-size' => 8 }
162
+ assert_equal expected, result
163
+ assert_equal 6, result.bytesize
164
+ end
165
+
166
+ test 'should allow maximize size of attribute value to be disabled' do
167
+ expected = 'a' * 5000
168
+ input = <<-EOS
169
+ :name: #{'a' * 5000}
170
+
171
+ {name}
172
+ EOS
173
+
174
+ result = render_embedded_string input, :doctype => :inline, :attributes => { 'max-attribute-value-size' => nil }
175
+ assert_equal expected, result
176
+ assert_equal 5000, result.bytesize
177
+ end
178
+
127
179
  test 'resolves user-home attribute if safe mode is less than SERVER' do
128
180
  input = <<-EOS
129
181
  :imagesdir: {user-home}/etc/images