Skip to content

Dot output need to escape < and > in labels #44

@lesnake

Description

@lesnake

When operators > and < are overloaded, this has the consequence to have the > and < in the label.

This characters needs escaping because, as stated in label formatting, these are used as field delimiters.
This class

  class Version < Array
    def initialize s
      str = s.gsub(/[\-_]/,".")
      super(str.split('.').map { |e| e.to_i })
    end
    def < x
      (self <=> x) < 0
    end
    def <= x
      (self <=> x) <= 0
    end
    def > x
      (self <=> x) > 0
    end
    def >= x
      (self <=> x) >= 0
    end
    def == x
      (self <=> x) == 0
    end
  end

Produces the following dot:

"Package::Version" [shape=Mrecord, label="{Package::Version|\l|I + initialize(s)\lI + <(x)\lI + <=(x)\lI + >(x)\lI + >=(x)\lI + ==(x)\l}"]

Which produces the following message when converting using dot

Error: bad label format {Metabuild::Version|\l|I + initialize(s)\lI + <(x)\lI + <=(x)\lI + >(x)\lI + >=(x)\lI + ==(x)\l}

Escaping each > and < in the label with a backslash solved the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions