os6sense / xumlidot

RUBY UML class diagram generator with XMI and DOT output.
MIT License
40 stars 7 forks source link

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

Open lesnake opened 2 years ago

lesnake commented 2 years ago

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.