summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtaniwaki <daisuketaniwaki@gmail.com>2016-02-27 20:42:56 -0800
committerdtaniwaki <daisuketaniwaki@gmail.com>2016-02-27 20:42:56 -0800
commit93b2cf96ea428d90fe972d360219aad270a548ce (patch)
treea334473a631412f0c89e0b73bf92fe0c9a230bc9
parent7cd9d6ce5623becdd8d20cd38708652b81666bad (diff)
downloadyamljs-93b2cf96ea428d90fe972d360219aad270a548ce.tar.gz
Ignore empty lines for smallest indent
-rw-r--r--src/Parser.coffee1
-rw-r--r--test/spec/YamlSpec.coffee3
2 files changed, 4 insertions, 0 deletions
diff --git a/src/Parser.coffee b/src/Parser.coffee
index 73c4d86..c0299d9 100644
--- a/src/Parser.coffee
+++ b/src/Parser.coffee
@@ -608,6 +608,7 @@ class Parser
lines = value.split("\n")
smallestIndent = -1
for line in lines
+ continue if Utils.trim(line, ' ').length == 0
indent = line.length - Utils.ltrim(line).length
if smallestIndent is -1 or indent < smallestIndent
smallestIndent = indent
diff --git a/test/spec/YamlSpec.coffee b/test/spec/YamlSpec.coffee
index 20c63e3..0d0f613 100644
--- a/test/spec/YamlSpec.coffee
+++ b/test/spec/YamlSpec.coffee
@@ -142,7 +142,10 @@ describe 'Parsed YAML Collections', ->
job: 'Accountant'
age: 38
+ it 'can ignore trailing empty lines for smallest indent', ->
+ expect YAML.parse """ trailing: empty lines\n"""
+ .toEqual trailing: 'empty lines'
describe 'Parsed YAML Inline Collections', ->