From a69e958bbd00c8fadc38792dbab661ab24714a47 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Fri, 13 May 2022 11:17:36 -0400 Subject: [PATCH] Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key. --- CHANGELOG.md | 4 ++++ lib/syntax_tree/node.rb | 2 +- test/fixtures/assoc.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe3030e9..07da8abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [Unreleased] +### Changed + +- Correct the pattern for checking if a dynamic symbol can be converted into a label as a hash key. + ## [2.4.1] - 2022-05-10 - [#73](https://github.com/ruby-syntax-tree/syntax_tree/pull/73) - Fix nested hash patterns from accidentally adding a `then` to their output. diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb index fdb40631..e8df1ea7 100644 --- a/lib/syntax_tree/node.rb +++ b/lib/syntax_tree/node.rb @@ -1388,7 +1388,7 @@ def format(q) module HashKeyFormatter # Formats the keys of a hash literal using labels. class Labels - LABEL = /^[@$_A-Za-z]([_A-Za-z0-9]*)?([!_=?A-Za-z0-9])?$/ + LABEL = /\A[A-Za-z_](\w*[\w!?])?\z/ def format_key(q, key) case key diff --git a/test/fixtures/assoc.rb b/test/fixtures/assoc.rb index cd3e5ed1..0fc60e6f 100644 --- a/test/fixtures/assoc.rb +++ b/test/fixtures/assoc.rb @@ -46,3 +46,5 @@ { foo: "bar" } % { "foo #{bar}": "baz" } +% +{ "foo=": "baz" }