@@ -503,7 +503,16 @@ export class XPathLexer {
503
503
if ( result . length > 0 ) {
504
504
let lastToken = result [ result . length - 1 ] ;
505
505
if ( lastToken . tokenType === TokenLevelState . string ) {
506
- XPathLexer . checkStringLiteralEnd ( lastToken ) ;
506
+ XPathLexer . checkExitStringLiteralEnd ( lastToken , result ) ;
507
+ } else if ( lastToken . tokenType === TokenLevelState . entityRef ) {
508
+ if ( result . length > 1 ) {
509
+ const nextLastToken = result [ result . length - 2 ] ;
510
+ if ( nextLastToken . tokenType === TokenLevelState . string ) {
511
+ if ( ! lastToken . value . endsWith ( '"' ) && ! lastToken . value . startsWith ( ''' ) ) {
512
+ lastToken [ 'error' ] = ErrorType . XPathStringLiteral ;
513
+ }
514
+ }
515
+ }
507
516
}
508
517
}
509
518
position . line = this . lineNumber ;
@@ -666,13 +675,30 @@ export class XPathLexer {
666
675
return result ;
667
676
}
668
677
678
+ public static checkExitStringLiteralEnd ( lastToken : BaseToken , result : BaseToken [ ] ) {
679
+ let followsEntityRef = false ;
680
+ if ( result . length > 1 ) {
681
+ const nextLastToken = result [ result . length - 2 ] ;
682
+ followsEntityRef = nextLastToken . tokenType === TokenLevelState . entityRef ;
683
+ }
684
+ if ( followsEntityRef ) {
685
+ let lastChar = lastToken . value . charAt ( lastToken . value . length - 1 ) ;
686
+ const lastCharIsSingleQuote = lastChar === "'" ;
687
+ if ( lastChar !== '"' && ! lastCharIsSingleQuote && ! lastToken . value . endsWith ( '"' ) && ! lastToken . value . startsWith ( ''' ) ) {
688
+ lastToken [ 'error' ] = ErrorType . XPathStringLiteral ;
689
+ }
690
+ } else {
691
+ this . checkStringLiteralEnd ( lastToken ) ;
692
+ }
693
+ }
694
+
669
695
public static checkStringLiteralEnd ( lastToken : BaseToken ) {
670
- let firstChar = lastToken . value . charAt ( 0 ) ;
671
696
let lastChar = lastToken . value . charAt ( lastToken . value . length - 1 ) ;
697
+ let firstChar = lastToken . value . charAt ( 0 ) ;
672
698
if ( ! ( ( lastChar === firstChar && lastToken . value . length > 1 ) || ( lastToken . value . length > 6 &&
673
699
( lastToken . value . startsWith ( '"' ) && lastToken . value . endsWith ( '"' ) ) || ( lastToken . value . startsWith ( ''' ) && lastToken . value . endsWith ( ''' ) ) ) ) ) {
674
700
lastToken [ 'error' ] = ErrorType . XPathStringLiteral ;
675
- }
701
+ }
676
702
}
677
703
678
704
private static closeMatchesOpen ( close : CharLevelState , stack : Token [ ] ) : boolean {
0 commit comments