From ebd771282951c8238bea8522534c25acf5d66c72 Mon Sep 17 00:00:00 2001 From: Akash Srivastava Date: Sat, 28 Nov 2020 03:26:52 +0530 Subject: [PATCH] fix: Parsing of preamble with escaped content in runkit tags (#11466) --- app/views/liquids/_runkit.html.erb | 2 +- .../article_with_runkit_tag_with_preamble.txt | 45 +++++++++++++++++++ .../articles/user_creates_an_article_spec.rb | 12 +++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/files/article_with_runkit_tag_with_preamble.txt diff --git a/app/views/liquids/_runkit.html.erb b/app/views/liquids/_runkit.html.erb index a17af16b7..15bcf8757 100644 --- a/app/views/liquids/_runkit.html.erb +++ b/app/views/liquids/_runkit.html.erb @@ -1,6 +1,6 @@
- <%= preamble %> + <%= CGI.unescapeHTML preamble %> <%= parsed_content %> diff --git a/spec/fixtures/files/article_with_runkit_tag_with_preamble.txt b/spec/fixtures/files/article_with_runkit_tag_with_preamble.txt new file mode 100644 index 000000000..b53bcf25b --- /dev/null +++ b/spec/fixtures/files/article_with_runkit_tag_with_preamble.txt @@ -0,0 +1,45 @@ +--- +title: Sample Article +published: true +description: this is a sample article +tags: test +--- + +Suspendisse ac lobortis velit, a feugiat sapien. Aenean condimentum, nulla at fermentum sagittis, tellus nisi suscipit velit, vel sollicitudin odio ligula a odio. Integer eget efficitur massa, in sodales velit. Nunc fermentum consequat scelerisque. Morbi elementum tristique faucibus. Nulla vel lectus non justo euismod varius. Vivamus id nisl sit amet odio tincidunt fringilla. Pellentesque odio odio, vulputate in risus eu, lacinia porttitor lorem. Nunc posuere tempus est, imperdiet suscipit odio maximus id. Nam eget feugiat magna. + +{% runkit %} +const node = data => next => callback => callback (data) (next) +// ---- ---- -------- ---- ---- +// \ | / / / +// parameters are curried ------------- +// / +// closures make data and next available +// to callback when it is finally called. + +// I can use bind to store my data and next values. +const head = node ('data') (null) +// ------ ---- +// / / +// We can partially apply the arguments `data` and null. + +// Use a callback to read the values from head. +head (data => next => { + return { data, next } +}) +{% endrunkit %} + + +{% runkit +const V = a => b => c => c (a) (b) +%} +const node = V + +const leftRight = node ('Left') ('Right') + +// TODO: modify callback so the code returns 'Left' +const callback = a => b => {} + +leftRight (callback) //=> 'Left' +{% endrunkit %} + + diff --git a/spec/system/articles/user_creates_an_article_spec.rb b/spec/system/articles/user_creates_an_article_spec.rb index 7d8ace182..2f8e9a8fb 100644 --- a/spec/system/articles/user_creates_an_article_spec.rb +++ b/spec/system/articles/user_creates_an_article_spec.rb @@ -8,6 +8,9 @@ RSpec.describe "Creating an article with the editor", type: :system do let!(:template_with_runkit_tag) do file_fixture("article_with_runkit_tag.txt").read end + let!(:template_with_runkit_tag_with_preamble) do + file_fixture("article_with_runkit_tag_with_preamble.txt").read + end before do sign_in user @@ -44,6 +47,15 @@ RSpec.describe "Creating an article with the editor", type: :system do expect_runkit_tag_to_be_active end + it "creates a new article with a Runkit tag with complex preamble" do + visit new_path + fill_in "article_body_markdown", with: "" + fill_in "article_body_markdown", with: template_with_runkit_tag_with_preamble + click_button "Save changes" + + expect_runkit_tag_to_be_active(count: 2) + end + # TODO: [@forem/sre] figure out why this fails intermittently :-| xit "previews article with a Runkit tag and creates it" do visit new_path