From e4547ca7cfe8ec6e69f60f1cf900ce332ec1c879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 8 Mar 2024 10:51:14 +0100 Subject: [PATCH] Remove `skip_space` at end of `Call` This `skip_space` would consume trailing comments, newlines and comments after newlines which on calls without parentheses. It would be fine to keep it when there are parentheses (because then we expect `OP_RPAREN`), but it seems to be entirely unnecessary. --- spec/compiler/formatter/formatter_spec.cr | 8 ++++++++ src/compiler/crystal/tools/formatter.cr | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spec/compiler/formatter/formatter_spec.cr b/spec/compiler/formatter/formatter_spec.cr index dc7578c736bf..2b014ba69d4e 100644 --- a/spec/compiler/formatter/formatter_spec.cr +++ b/spec/compiler/formatter/formatter_spec.cr @@ -2893,6 +2893,14 @@ describe Crystal::Formatter do end end + # #14256 + assert_format <<-CRYSTAL + foo bar # comment + + # doc + def baz; end + CRYSTAL + # CVE-2021-42574 describe "Unicode bi-directional control characters" do ['\u202A', '\u202B', '\u202C', '\u202D', '\u202E', '\u2066', '\u2067', '\u2068', '\u2069'].each do |char| diff --git a/src/compiler/crystal/tools/formatter.cr b/src/compiler/crystal/tools/formatter.cr index 0d7a6115ca71..d6559bac9014 100644 --- a/src/compiler/crystal/tools/formatter.cr +++ b/src/compiler/crystal/tools/formatter.cr @@ -2981,8 +2981,6 @@ module Crystal end def finish_args(has_parentheses, has_newlines, ends_with_newline, found_comment, column) - skip_space - if has_parentheses if @token.type.op_comma? next_token