From 026f8280e0434be0b44e67b4d423b723c9306b5a Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Tue, 18 Jul 2017 12:59:33 +0530 Subject: [PATCH] Ignore final newline in folded YAML string (#6054) Merge pull request 6054 --- lib/site_template/_config.yml | 2 +- test/source/_config_folded.yml | 8 ++++++++ test/test_configuration.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/source/_config_folded.yml diff --git a/lib/site_template/_config.yml b/lib/site_template/_config.yml index 5cea6d25d54..f91333e5102 100644 --- a/lib/site_template/_config.yml +++ b/lib/site_template/_config.yml @@ -15,7 +15,7 @@ # in the templates via {{ site.myvariable }}. title: Your awesome title email: your-email@example.com -description: > # this means to ignore newlines until "baseurl:" +description: >- # this means to ignore newlines until "baseurl:" Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description. diff --git a/test/source/_config_folded.yml b/test/source/_config_folded.yml new file mode 100644 index 00000000000..9b0bfa4c2c5 --- /dev/null +++ b/test/source/_config_folded.yml @@ -0,0 +1,8 @@ +folded_string: > + This string of text will ignore + newlines till the next key. +foo: bar +clean_folded_string: >- + This string of text will ignore + newlines till the next key. +baz: foo diff --git a/test/test_configuration.rb b/test/test_configuration.rb index c9988d163bc..50156926202 100644 --- a/test/test_configuration.rb +++ b/test/test_configuration.rb @@ -494,4 +494,36 @@ class TestConfiguration < JekyllUnitTest }) end end + + context "folded YAML string" do + setup do + @tester = Configuration.new + end + + should "ignore newlines in that string entirely from a sample file" do + config = Jekyll.configuration( + @tester.read_config_file( + source_dir("_config_folded.yml") + ) + ) + assert_equal( + config["folded_string"], + "This string of text will ignore newlines till the next key.\n" + ) + assert_equal( + config["clean_folded_string"], + "This string of text will ignore newlines till the next key." + ) + end + + should "ignore newlines in that string entirely from the template file" do + config = Jekyll.configuration( + @tester.read_config_file( + File.expand_path("../lib/site_template/_config.yml", File.dirname(__FILE__)) + ) + ) + assert_includes config["description"], "an awesome description" + refute_includes config["description"], "\n" + end + end end