Skip to content

erb-format is deleting text from the copy of a template file #80

Description

@jbranchaud

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:

Image

What is perhaps odder is that subsequent runs of the formatter against the "formatted" file then remove additional pairs of characters.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions