Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Why is Rails gsub adding </script> tags
unsafe_input = ActionController::Base.helpers.escape_javascript("'hi'") # comes from user input
html = "<script>console.log('((url))');</script>"
html.gsub("((url))", unsafe_input)

output: "<script>console.log('');</script>hi');</script>');</script>"

expected: <script>console.log('\'hi\'');</script>

I'm trying to build dynamic HTML to inject on the page. This html is a mix of my own (safe) html, and any unsafe code (in the example above, unsafe_input) is ran through escape_javascript and inserted ONLY between single quotes in a javascript variable.

I don't use escape_javascript in the view as building the html is quite complicated and I don't want to do it all inside the view... I do it in a model using the helper, and in the html I simply have:

<%= @combined_html.html_safe %>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda