Skip to content

Conversation

@takaokouji
Copy link

Summary

This PR fixes an issue where control characters (e.g., \n, \t) in Ruby code generation were not properly escaped, causing multi-line strings or literal tabs in the output Ruby code.

Changes

  • Updated RubyGenerator.escapeChars_ in src/lib/ruby-generator/index.js to include:
    • \n (newline)
    • \t (tab)
    • \r (carriage return)
    • \b (backspace)
    • \f (form feed)
    • \v (vertical tab)
    • \0 (null)
  • Added direct unit tests for RubyGenerator.quote_ in test/unit/lib/ruby-generator/index.test.js.
  • Added unit tests for print and puts blocks with control characters in test/unit/lib/ruby-generator/looks.test.js.

Verification Results

  • All unit tests passed (npm run test:unit).
  • Lint check passed (npm run test:lint).

Fixes smalruby/smalruby3-develop#28

Updated RubyGenerator.escapeChars_ to include control characters:
- \n (newline)
- \t (tab)
- \r (carriage return)
- \b (backspace)
- \f (form feed)
- \v (vertical tab)
- \0 (null)

Added unit tests to verify escaping of these characters.

Fixes smalruby/smalruby3-develop#28
Update operators.test.js to match fix for issue #28.
Correctly use backslashes in dedent template literals to expect literal \n and \.
This matches the Ruby code generator's behavior of escaping control characters.
Avoid dedent's unpredictable backslash handling by using String.raw.
This ensures the test expectation accurately matches the generator's output.
@takaokouji takaokouji merged commit 5ac2763 into develop Jan 18, 2026
3 checks passed
@takaokouji takaokouji deleted the fix/issue-28-escape-control-characters branch January 18, 2026 12:30
github-actions bot pushed a commit that referenced this pull request Jan 18, 2026
…escape-control-characters

fix: escape control characters in Ruby code generation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: escape control characters in Ruby code generation

2 participants