Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Feature/scalar raw value #6

Merged

Conversation

menduz
Copy link
Contributor

@menduz menduz commented Sep 30, 2016

Added allowAnyEscape option to parser.

name: "Agustin \{test}"

Is now parsed as Scalar "Agustin \\{test}"

Added rawValue to Scalar, lets use this yaml fragment:

test: "hola\nmanola\{"

Before, and now without the new flag, we expect this result:

let yaml = `
test: "hola${'\\'}nmanola${'\\'}{"
`;

let result = yaml.load(yaml); 

result == { errors:
   [ YAMLException {
       name: 'YAMLException',
       reason: 'unknown escape sequence',
       mark:
        Mark {
          name: null,
          buffer: '\ntest: "hola\\nmanola\\{"\n\u0000',
          position: 21,
          line: 0,
          column: 20 },
       message: 'JS-YAML: unknown escape sequence at line 1, column 21' } ],
   ...
}

Now it works with the new allowAnyEscape flag

let options = { allowAnyEscape: true };
let yaml = `
test: "hola${'\\'}nmanola${'\\'}{"
`;

let result = yaml.load(yaml, options);

result == { errors: [],
  startPosition: 1,
  endPosition: 24,
  mappings:
   [ { key:
        { errors: [],
          startPosition: 1,
          endPosition: 5,
          value: 'test',
          kind: 0,
          parent: [Circular],
          doubleQuoted: false,
          rawValue: 'test',
          plainScalar: true },
       value:
        { errors: [],
          startPosition: 7,
          endPosition: 23,
          value: 'hola\nmanola\\{',
          kind: 0,
          parent: [Circular],
          doubleQuoted: true,
          rawValue: '"hola\\nmanola\\{"' }, // <-----
       startPosition: 1,
       endPosition: 23,
       kind: 1,
       parent: [Circular],
       errors: [] } ],
  kind: 2,
  parent: null }

@menduz
Copy link
Contributor Author

menduz commented Sep 30, 2016

It also solves #5

@KonstantinSviridov
Copy link
Contributor

Hi, @menduz!

Thanks for the contribution.

@KonstantinSviridov KonstantinSviridov merged commit 84445e2 into mulesoft-labs:master Oct 4, 2016
@menduz
Copy link
Contributor Author

menduz commented Oct 4, 2016

@KonstantinSviridov thank you. Please also check PR #4

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants