erb-formatter
erb-formatter copied to clipboard
erb-format is deleting text from the copy of a template file
trafficstars
I ran into this in a codebase and was able to put together this reproduction.
$ erb-format --version
ERB::Formatter 0.7.3
Here is the repro template where Case 1 gets mangled by the formatter whereas Case 2 and Case 3 are untouched:
<%# Test data inline
checkout =
OpenStruct.new(
status: :overdue,
loan_period: OpenStruct.new(name: "Standard"),
)
next_fine =
OpenStruct.new(assessed_date: Date.new(2024, 3, 15), amount_owed: 12.50) %>
<div class="patron-details">
<!-- Case 1: Text "fine" after dot character -->
<div>
<%= checkout.status %>
- fine
<%= next_fine.assessed_date.strftime("%b %d") %>
@ branch •
<%= checkout.status == :overdue ? "Current" : "Pending" %> fine as of
<%= next_fine.assessed_date.strftime("%b %d") %> totaling
<%= number_to_currency next_fine.amount_owed %>
</div>
<!-- Case 2: Text "fine" after wrapped dot character -->
<div>
<%= checkout.status %>
- fine
<%= next_fine.assessed_date.strftime("%b %d") %>
@ branch
<%= "•" %>
<%= checkout.status == :overdue ? "Current" : "Pending" %>
fine as of
<%= next_fine.assessed_date.strftime("%b %d") %>
totaling
<%= number_to_currency next_fine.amount_owed %>
</div>
<!-- Case 3: Extra minimal -->
<div>
Text •
<%= checkout.status == :overdue ? "Current" : "Pending" %>
fine as of
</div>
</div>
Here is what the diff looks like:
What is perhaps odder is that subsequent runs of the formatter against the "formatted" file then remove additional pairs of characters.
Oh my, multi-codepoint emojis really do a number on it. I think this is a case of StringScanner#pos vs StringScanner#charpos.