Use Base64 to pass text through compiled erb templates #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a proposed way to potentially reduce confusion in the error highlighter in rails.
The problem is partly that the highlighter looks for the source erb expressions in the compiled template. I addressed this problem in rails/rails#53657 by making the error highlighter more tolerant of this situation. It also occurs in rails easily, for example searching for a space between erb tags. Now the highlighter succeeds more often.
The other big problem is that multi-line blocks of code get double the newlines added to the compiled template. This causes the highlighter to fail to find the correct line in the first place and, until rails/rails#53696 merges, this can cause the highlighter to crash completely.
I think the main reason for this is the duplication of the code in the template. For this I propose encoding the string version of the template with base64 (urlsafe doesn't add a newline that I have to trim). This keeps the string version of the code from visibly existing in the template.
Hopefully someone with more experience with better-html can validate this approach.