From da79da636baa790cfceda931554186ac17f7f48b Mon Sep 17 00:00:00 2001 From: Aboobacker MK Date: Mon, 19 Aug 2024 08:38:36 +0530 Subject: [PATCH] fix(ruby) - fix `|=` operator false positives (as block arguments) (#4093) * Fix block parameter handling ruby in ruby block parameter can be enclosed with |. But ruby also has builtin operator |=. This PR ensure that |= is not marked as be the beginning of the block parameter. --- CHANGES.md | 2 ++ src/languages/ruby.js | 2 +- test/markup/ruby/blocks.expect.txt | 7 +++++++ test/markup/ruby/blocks.txt | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/markup/ruby/blocks.expect.txt create mode 100644 test/markup/ruby/blocks.txt diff --git a/CHANGES.md b/CHANGES.md index d8ef2f8890..10744aeb44 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Core Grammars: - enh(erlang) OTP25/27 maybe statement [nixxquality][] - enh(dart) Support digit-separators in number literals [Sam Rawlins][] - enh(csharp) add Contextual keywords `file`, `args`, `dynamic`, `record`, `required` and `scoped` [Alvin Joy][] +- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK] New Grammars: @@ -37,6 +38,7 @@ CONTRIBUTORS [nixxquality]: https://github.com/nixxquality [srawlins]: https://github.com/srawlins [Alvin Joy]: https://github.com/alvinsjoy +[Aboobacker MK]: https://github.com/tachyons ## Version 11.10.0 diff --git a/src/languages/ruby.js b/src/languages/ruby.js index 026580e52b..91b2cb527d 100644 --- a/src/languages/ruby.js +++ b/src/languages/ruby.js @@ -350,7 +350,7 @@ export default function(hljs) { }, { className: 'params', - begin: /\|/, + begin: /\|(?!=)/, end: /\|/, excludeBegin: true, excludeEnd: true, diff --git a/test/markup/ruby/blocks.expect.txt b/test/markup/ruby/blocks.expect.txt new file mode 100644 index 0000000000..b44cd5ab8f --- /dev/null +++ b/test/markup/ruby/blocks.expect.txt @@ -0,0 +1,7 @@ +[1, 2, 3].each do |num| + puts num +end + +names |= users.map do |user| + user.name +end diff --git a/test/markup/ruby/blocks.txt b/test/markup/ruby/blocks.txt new file mode 100644 index 0000000000..f9cda6d09a --- /dev/null +++ b/test/markup/ruby/blocks.txt @@ -0,0 +1,7 @@ +[1, 2, 3].each do |num| + puts num +end + +names |= users.map do |user| + user.name +end