| | @@ -4532,10 +4532,39 @@ |
| 4532 | 4532 | } |
| 4533 | 4533 | memcpy(p->zOut+p->nOut, zText, n); |
| 4534 | 4534 | p->nOut += n; |
| 4535 | 4535 | p->zOut[p->nOut] = 0; |
| 4536 | 4536 | } |
| 4537 | + |
| 4538 | +/* |
| 4539 | +** Given a string and its length, returns true if the string begins |
| 4540 | +** with a construct which syntactically matches an HTML entity escape |
| 4541 | +** sequence (without checking for whether it's a known entity). Always |
| 4542 | +** returns false if zText[0] is false or n<4. Entities match the |
| 4543 | +** equivalent of the regexes `&#[0-9]+;` and `&[a-zA-Z]+;`. |
| 4544 | +*/ |
| 4545 | +static int pik_isentity(char const * zText, int n){ |
| 4546 | + int i = 0; |
| 4547 | + if( n<4 || '&'!=zText[0] ) return 0; |
| 4548 | + n--; |
| 4549 | + zText++; |
| 4550 | + if( '#'==zText[0] ){ |
| 4551 | + zText++; |
| 4552 | + n--; |
| 4553 | + for(i=0; i<n; i++){ |
| 4554 | + if( i>1 && ';'==zText[i] ) return 1; |
| 4555 | + else if( zText[i]<'0' || zText[i]>'9' ) return 0; |
| 4556 | + } |
| 4557 | + }else{ |
| 4558 | + for( i=0; i<n; i++ ){ |
| 4559 | + if( i>1 && ';'==zText[i] ) return 1; |
| 4560 | + else if( zText[i]<'A' || zText[i]>'z' |
| 4561 | + || (zText[i]>'Z' && zText[i]<'a') ) return 0; |
| 4562 | + } |
| 4563 | + } |
| 4564 | + return 0; |
| 4565 | +} |
| 4537 | 4566 | |
| 4538 | 4567 | /* |
| 4539 | 4568 | ** Append text to zOut with HTML characters escaped. |
| 4540 | 4569 | ** |
| 4541 | 4570 | ** * The space character is changed into non-breaking space (U+00a0) |
| | @@ -4564,12 +4593,14 @@ |
| 4564 | 4593 | if( i ) pik_append(p, zText, i); |
| 4565 | 4594 | if( i==n ) break; |
| 4566 | 4595 | switch( c ){ |
| 4567 | 4596 | case '<': { pik_append(p, "<", 4); break; } |
| 4568 | 4597 | case '>': { pik_append(p, ">", 4); break; } |
| 4569 | | - case '&': { pik_append(p, "&", 5); break; } |
| 4570 | 4598 | case ' ': { pik_append(p, "\302\240;", 2); break; } |
| 4599 | + case '&': |
| 4600 | + if( pik_isentity(zText+i, n-i) ){ pik_append(p, "&", 1); } |
| 4601 | + else { pik_append(p, "&", 5); } |
| 4571 | 4602 | } |
| 4572 | 4603 | i++; |
| 4573 | 4604 | n -= i; |
| 4574 | 4605 | zText += i; |
| 4575 | 4606 | i = 0; |
| | @@ -8096,6 +8127,6 @@ |
| 8096 | 8127 | |
| 8097 | 8128 | |
| 8098 | 8129 | #endif /* PIKCHR_TCL */ |
| 8099 | 8130 | |
| 8100 | 8131 | |
| 8101 | | -#line 8126 "pikchr.c" |
| 8132 | +#line 8157 "pikchr.c" |
| 8102 | 8133 | |