Skip to content

No accommodation for leading semicolon or > 2 codes #8

@johlym

Description

@johlym

We found an issue in the ANSI code matching that doesn't work well with a couple different ANSI combinations.

Case 1:
If a user has the valid code of 0;33;49m, the logic only identifies 0 and 33 for conversion to HTML and ignores 49.

We found a much older variant of the code, which I can no longer find in the history (or perhaps was from another library this one forked from way back when) didn't specifically choose slots 1 and 2, but rather just iterated through all:

return str.replace(/\x1b\[([0-9\;]+)m/g, function(match, codeSequence) {
      var i, code, res = ''
      codes = codeSequence.split(';')
      for (i = 0; i < codes.length; i++) {
        if (!codes[i]) continue
        code = parseInt(codes[i])

        res = tag(code)
      }
      return res
    }) + tag();

Case 2:
If a user has the valid code of ;33m, the logic only identifies 33 and ignores the leading semicolon. According to [the spec](www.ecma-international.org/publications/files/ECMA-ST/ECMA-48, 3rd Edition, March 1984.pdf) (5.4.11), a leading semicolon should be treated as an empty value; an empty value should be treated as 0. In short: ;33m == 0;33m.

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