Commit a98066c
authored
Fix parsing xpath that has string literal containing parentheses and brackets (#318)
String literal in XPath 1.0 doesn't have escapes.
`begin end while cond` is not a normal modifier while, but a do-while
loop. (I didn't know it). REXML uses this syntax in several files.
Removes preprocessing that removes spaces with gsub which may wrongly
modifies string literal.
Also fixes error parsing `//a[1] [2]`.
All test except exact-error-message test and the one I added in this PR
passed with:
```ruby
def parse path
path = path.gsub('(', '( ').gsub(/[\)\[\]]/, ' \0 ') # Insert space around paren/bracket
```
REF: https://www.w3.org/TR/xpath-10/#exprlex
> For readability, whitespace may be used in expressions even though not
explicitly allowed by the grammar: ExprWhitespace may be freely added
within patterns before or after any ExprToken.1 parent 2732516 commit a98066c
3 files changed
Lines changed: 54 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
| |||
359 | 356 | | |
360 | 357 | | |
361 | 358 | | |
362 | | - | |
| 359 | + | |
363 | 360 | | |
364 | | - | |
365 | | - | |
366 | | - | |
| 361 | + | |
367 | 362 | | |
368 | 363 | | |
369 | | - | |
| 364 | + | |
370 | 365 | | |
371 | | - | |
372 | 366 | | |
| 367 | + | |
373 | 368 | | |
374 | 369 | | |
375 | 370 | | |
| |||
400 | 395 | | |
401 | 396 | | |
402 | 397 | | |
| 398 | + | |
403 | 399 | | |
404 | 400 | | |
405 | 401 | | |
| |||
678 | 674 | | |
679 | 675 | | |
680 | 676 | | |
| 677 | + | |
681 | 678 | | |
682 | | - | |
683 | | - | |
684 | | - | |
685 | | - | |
686 | | - | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
687 | 691 | | |
688 | 692 | | |
689 | 693 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
114 | 132 | | |
115 | 133 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
833 | 851 | | |
834 | 852 | | |
835 | 853 | | |
| |||
0 commit comments