Skip to content

Single quotes inside hash value strings in haml are not escaped #895

Closed
@rsslldnphy

Description

@rsslldnphy

Metadata

  • Ruby version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
  • Node version: v15.12.0
  • @prettier/plugin-ruby "^1.5.5"
  • Options: all default options

Input

%div{title: "escaping quotes, it's annoying"}

Current Output

%div{title: 'escaping quotes, it's annoying'}

Expected output

Either:

%div{title: 'escaping quotes, it\'s annoying'}

Or:

%div{title: "escaping quotes, it's annoying"}

Problem description

Single quotes aren't escaped when converting double quotes to single quotes in hash values in HAML. From what I can see in ruby files double quotes are left in place if there's a single quote inside the string. This is a similar - but different - issue to #850. I started putting a pull request together but stopped as I realised it's probably more complex than just value.replace(/\\?'/, "\\'") - possibly need to take into account string values nested inside interpolation too? - so thought I'd raise it here before continuing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions