Skip to content

REXML::Text#indent_text broken since v3.2.6 #273

Open
@pboling

Description

@pboling

Version 3.2.6 of this gem released a major performance improvement from #94 which was largely the result of freezing strings by default, by adding the magoc comment to many files:

# frozen_string_literal: true

The following method from the REXML::Text class has never worked since that time, because it modifies frozen strings in multiple places.

    def indent_text(string, level=1, style="\t", indentfirstline=true)
      return string if level < 0
      new_string = ''
      string.each_line { |line|
        indent_string = style * level
        new_line = (indent_string + line).sub(/[\s]+$/,'')
        new_string << new_line
      }
      new_string.strip! unless indentfirstline
      return new_string
    end

I did not catch this myself, rather my IDE (RubyMine) noticed it and redlined it for me.

The fact this has never been reported (until now) is likely the result of a few factors:

  1. It is an instance method that is unrelated to the instance. There is never a reason to call this method on an instance of Text, and it doesn't use Text. Instead it operates on a string passed in as an argument.
  2. The method is never called by any code within the gem.
  3. There are no tests for the method.
  4. There is a different indent_text method in the Pretty formatter which probably gets used, and is called from internal code.

As a result I propose we do one of the following:

  • Deprecate REXML::Text#indent_text, but leave it broken, resulting in throwing an error, as it has since v3.2.6. Remove in v4.
  • Deprecate REXML::Text#indent_text, but fix it. Remove in v4.

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