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" }