From d42172022fd07a4a89641cb80dcbe650302a0bc9 Mon Sep 17 00:00:00 2001 From: Serj Prikhodko Date: Tue, 23 Jan 2024 10:23:46 +0100 Subject: [PATCH] Replace `regexp` check with `parse` --- lib/unparser/emitter/primitive.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/unparser/emitter/primitive.rb b/lib/unparser/emitter/primitive.rb index 57f42ec..7eae0ef 100644 --- a/lib/unparser/emitter/primitive.rb +++ b/lib/unparser/emitter/primitive.rb @@ -26,15 +26,24 @@ class Symbol < self private - # mutant:disable + def dispatch - if RUBY_VERSION < '3.2' && value.match?(/=\z/) + if inspect_breaks_parsing? write(":#{value.name.inspect}") else write(value.inspect) end end + # mutant:disable + def inspect_breaks_parsing? + return false unless RUBY_VERSION < '3.2.' + + Unparser.parse(value.inspect) + false + rescue Parser::SyntaxError + true + end end # Symbol # Emitter for complex literals