Changeset 586 for proto


Ignore:
Timestamp:
Aug 20, 2010, 11:42:13 AM (9 years ago)
Author:
lindanl
Message:

Check if all character references expand to legal characters

Location:
proto/parabix2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/parabix2_compilable.py

    r584 r586  
    409409        tag_marks = callouts.EmptyTagMarks | LAngleFollow | AttNameStarts
    410410        NameFollows = ElemNameFollows | AttNameFollows
    411         return (CT_callouts, callouts, refs, error, lex, EOF_mask, name_check, name_start_check, control, tag_marks, NameFollows, CD_starts, GenRef2)
    412 
    413        
     411        return (CT_callouts, callouts, refs, error, lex, EOF_mask, name_check, name_start_check, control, tag_marks, NameFollows, CD_starts, GenRef2, DecRef3, HexRef4)
     412
     413       
  • proto/parabix2/template_tag_match.c

    r584 r586  
    186186              fprintf(stderr, "Undefined Reference found at position %i\n",block_pos+buffer_base);
    187187              exit(-1);
     188        }
     189        return 0;
     190}
     191
     192static inline int HexRef_check(int pos) {
     193        int block_pos = block_base + pos;
     194        unsigned char* s = (unsigned char*)&source[block_pos];
     195        int ch_val = 0;
     196        while(at_HexDigit<ASCII>(s)){
     197          ch_val = HexVal<ASCII>(s[0]) + (ch_val<<4);
     198          if (ch_val> 0x10FFFF ){
     199            fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     200            exit(-1);
     201          }
     202          s++;
     203        }
     204        if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){
     205          fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     206          exit(-1);
     207        }
     208        else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){
     209          fprintf(stderr, "Illegal XML 1.0 character reference found at position %i\n",block_pos+buffer_base);
     210          exit(-1);
     211        }
     212        return 0;
     213}
     214
     215static inline int DecRef_check(int pos) {
     216        int block_pos = block_base + pos;
     217        unsigned char* s = (unsigned char*)&source[block_pos];
     218        int ch_val = 0;
     219        while(at_HexDigit<ASCII>(s)){
     220          ch_val = DigitVal<ASCII>(s[0]) + ch_val*10;
     221          if (ch_val> 0x10FFFF ){
     222            fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     223            exit(-1);
     224          }
     225          s++;
     226        }
     227        if ((ch_val == 0x0) || ((ch_val | 0x7FF) == 0xDFFF)|| ((ch_val | 0x1) == 0xFFFF)){
     228          fprintf(stderr, "Illegal character reference found at position %i\n",block_pos+buffer_base);
     229          exit(-1);
     230        }
     231        else if (((ch_val < 0x20) && (ch_val != 0x9) && (ch_val != 0xD) && (ch_val != 0xA))){
     232          fprintf(stderr, "Illegal XML 1.0 character reference found at position %i\n",block_pos+buffer_base);
     233          exit(-1);
    188234        }
    189235        return 0;
     
    355401        }
    356402       
     403        if (bitblock_has_bit(DecRef3)){
     404          StreamScan((ScanBlock *) &DecRef3, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check);
     405        }
     406       
     407        if (bitblock_has_bit(HexRef4)){
     408          StreamScan((ScanBlock *) &HexRef4, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check);
     409        }
     410       
    357411        t.store_streams(tag_marks, NameFollows);
    358412       
     
    401455        if (bitblock_has_bit(GenRef2)){
    402456          StreamScan((ScanBlock *) &GenRef2, sizeof(BitBlock)/sizeof(ScanBlock), GenRef_check);
     457        }
     458       
     459        if (bitblock_has_bit(DecRef3)){
     460          StreamScan((ScanBlock *) &DecRef3, sizeof(BitBlock)/sizeof(ScanBlock), DecRef_check);
     461        }
     462       
     463        if (bitblock_has_bit(HexRef4)){
     464          StreamScan((ScanBlock *) &HexRef4, sizeof(BitBlock)/sizeof(ScanBlock), HexRef_check);
    403465        }
    404466       
Note: See TracChangeset for help on using the changeset viewer.