atom / language-ruby

Ruby package for Atom
Other
101 stars 144 forks source link

feat(ruby.cson) support quoted heredoc literals #212

Closed rmosolgo closed 6 years ago

rmosolgo commented 7 years ago

Thanks for maintaining this project and considering my PR!

Description of the Change

Ruby supports quoted heredocs:

  string1 = <<-STR
    Hello World
  STR

  string2 = <<-"STR"
    Hello World
  STR

  string3 = <<-'STR'
    Hello World
  STR

  shell_block = <<-`COMMAND`
    ls ~
    pwd
  COMMAND

But they aren't captured by the current grammar. This change adds quotes to the heredoc regexps so that they'll be properly tokenized.

Alternate Designs

No alternate deisgns were considered.

Benefits

We use single-quoted heredocs to assert that interpolation is not possible. This is a security check: interpolation can lead to various injection bugs.

Embedded code is not highlighted right now:

image

But after this change, it will be highlighted!

Possible Drawbacks

Added complexity to the heredoc regexp.

Applicable Issues

I didn't find any.

rmosolgo commented 7 years ago

@50Wliu Does this concept sound ok to you?

winstliu commented 7 years ago

I'll get around to it soon. Without looking at the code changes, it sounds like a good thing to add support for.

rmosolgo commented 7 years ago

Thanks for taking a quick look, glad to hear I'm on the right track :)

rmosolgo commented 6 years ago

👋 Hi, if someone has a chance, I'd appreciate a review of this! (or feel free to close it, if it's not a good fit for merging.)

lee-dohm commented 6 years ago

@maxbrunsfeld Can you take a look here perhaps?

daviwil commented 6 years ago

Hi @rmosolgo, thanks a lot for the PR! The grammar changes look good to me, but do you mind adding an additional case to test backtick quoting? Once that's done this PR should be good to merge!

daviwil commented 6 years ago

Just realized I can easily just add the extra case through the web editor :) Once CI passes I'll get this merged and updated!

rmosolgo commented 6 years ago

Woah, thanks! I'm looking forward to using this 😊