@@ -119,9 +119,16 @@ function charFromCodepoint(c) {
119119
120120var simpleEscapeCheck = new Array ( 256 ) ; // integer, for fast access
121121var simpleEscapeMap = new Array ( 256 ) ;
122+ var customEscapeCheck = new Array ( 256 ) ; // integer, for fast access
123+ var customEscapeMap = new Array ( 256 ) ;
122124for ( var i = 0 ; i < 256 ; i ++ ) {
123- simpleEscapeCheck [ i ] = simpleEscapeSequence ( i ) ? 1 : 0 ;
124- simpleEscapeMap [ i ] = simpleEscapeSequence ( i ) ;
125+ customEscapeMap [ i ] = simpleEscapeMap [ i ] = simpleEscapeSequence ( i ) ;
126+ simpleEscapeCheck [ i ] = simpleEscapeMap [ i ] ? 1 : 0 ;
127+ customEscapeCheck [ i ] = 1 ;
128+
129+ if ( ! simpleEscapeCheck [ i ] ) {
130+ customEscapeMap [ i ] = '\\' + String . fromCharCode ( i ) ;
131+ }
125132}
126133
127134
@@ -151,14 +158,16 @@ class State{
151158 tagMap :any
152159 version :string
153160 checkLineBreaks :boolean
161+ allowAnyEscape :boolean
154162
155163 constructor ( input :string , options :any ) {
156164 this . input = input ;
157165
158166 this . filename = options [ 'filename' ] || null ;
159167 this . schema = options [ 'schema' ] || DEFAULT_FULL_SCHEMA ;
160168 this . onWarning = options [ 'onWarning' ] || null ;
161- this . legacy = options [ 'legacy' ] || false ;
169+ this . legacy = options [ 'legacy' ] || false ;
170+ this . allowAnyEscape = options [ 'allowAnyEscape' ] || false ;
162171
163172 this . implicitTypes = this . schema . compiledImplicit ;
164173 this . typeMap = this . schema . compiledTypeMap ;
@@ -571,6 +580,7 @@ function readPlainScalar(state:State, nodeIndent, withinFlowCollection) {
571580 captureSegment ( state , captureStart , captureEnd , false ) ;
572581
573582 if ( state . result . startPosition != - 1 ) {
583+ state_result . rawValue = state . input . substring ( state_result . startPosition , state_result . endPosition ) ;
574584 return true ;
575585 }
576586
@@ -655,6 +665,7 @@ function readDoubleQuotedScalar(state:State, nodeIndent:number) {
655665 captureSegment ( state , captureStart , state . position , true ) ;
656666 state . position ++ ;
657667 scalar . endPosition = state . position ;
668+ scalar . rawValue = state . input . substring ( scalar . startPosition , scalar . endPosition ) ;
658669 return true ;
659670
660671 } else if ( 0x5C /* \ */ === ch ) {
@@ -665,8 +676,8 @@ function readDoubleQuotedScalar(state:State, nodeIndent:number) {
665676 skipSeparationSpace ( state , false , nodeIndent ) ;
666677
667678 // TODO: rework to inline fn with no type cast?
668- } else if ( ch < 256 && simpleEscapeCheck [ ch ] ) {
669- scalar . value += simpleEscapeMap [ ch ] ;
679+ } else if ( ch < 256 && ( state . allowAnyEscape ? customEscapeCheck [ ch ] : simpleEscapeCheck [ ch ] ) ) {
680+ scalar . value += ( state . allowAnyEscape ? customEscapeMap [ ch ] : simpleEscapeMap [ ch ] ) ;
670681 state . position ++ ;
671682
672683 } else if ( ( tmp = escapedHexLen ( ch ) ) > 0 ) {
@@ -981,6 +992,7 @@ function readBlockScalar(state:State, nodeIndent) {
981992
982993 }
983994 sc . endPosition = i ;
995+ sc . rawValue = state . input . substring ( sc . startPosition , sc . endPosition ) ;
984996 return true ;
985997}
986998
0 commit comments