Skip to content

Number codes e.g. ^^1 and ^1 in the input string produce the same output #10

@mkapal

Description

@mkapal

Current behaviour

When an input string contains an LFS colour code e.g. ^1, it is left intact, so the output string is also ^1.

When an input string contains ^^1, the first two ^ are un-escaped as ^, so it is decoded as ^1, which produces the same output as the case above.

This means there is no way of knowing if the original input string was coloured or contained a literal ^ character with a single digit after it.

This behaviour is covered by the unit tests:

expect(parseLFSMessage("^1")).toEqual("^1");

expect(parseLFSMessage("^^1")).toEqual("^1");

Expected behaviour

The parseLFSMessage function could parse the LFS colour codes into object tokens and return them in an array. Then the consumer program would decide how to handle the colours - strip them, convert them into HTML etc.

Example:

const tokens = parseLFSMessage('^1Hello^2World^^3Bye')

console.log(tokens);
[
  {
    string: 'Hello',
    color: 'red',
  },
  {
    string: 'World^3Bye',
    color: 'yellow',
  },
]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions