@@ -124,7 +124,7 @@ private String newStringIntern( char[] cbuf, int off, int len )
124
124
// private String elValue[];
125
125
private int elNamespaceCount [];
126
126
127
- private String fileEncoding = "UTF8" ;
127
+ private String fileEncoding = null ;
128
128
129
129
/**
130
130
* Make sure that we have enough space to keep element stack if passed size. It will always create one additional
@@ -587,8 +587,8 @@ else if ( FEATURE_XML_ROUNDTRIP.equals( name ) )
587
587
}
588
588
}
589
589
590
- /**
591
- * Unknown properties are <strong>always</strong> returned as false
590
+ /**
591
+ * Unknown properties are <strong>always</strong> returned as false
592
592
*/
593
593
@ Override
594
594
public boolean getFeature ( String name )
@@ -2677,7 +2677,15 @@ else if ( ch == '\t' || ch == '\n' || ch == '\r' )
2677
2677
2678
2678
private char [] charRefOneCharBuf = new char [1 ];
2679
2679
2680
- private char [] parseEntityRef ()
2680
+ /**
2681
+ * parse Entity Ref, either a character entity or one of the predefined name entities.
2682
+ *
2683
+ * @return -1 if found a valid character reference, or one of the predefined character reference names
2684
+ * (charRefOneCharBuf contains the replaced char). Returns the length of the found entity name, otherwise.
2685
+ * @throws XmlPullParserException if invalid XML is detected.
2686
+ * @throws IOException if an I/O error is found.
2687
+ */
2688
+ private int parseCharOrPredefinedEntityRef ()
2681
2689
throws XmlPullParserException , IOException
2682
2690
{
2683
2691
// entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference
@@ -2777,12 +2785,12 @@ else if ( ch >= 'A' && ch <= 'F' )
2777
2785
{
2778
2786
text = newString ( charRefOneCharBuf , 0 , charRefOneCharBuf .length );
2779
2787
}
2780
- return charRefOneCharBuf ;
2788
+ return - 1 ;
2781
2789
}
2782
2790
else
2783
2791
{
2784
2792
// [68] EntityRef ::= '&' Name ';'
2785
- // scan anem until ;
2793
+ // scan name until ;
2786
2794
if ( !isNameStartChar ( ch ) )
2787
2795
{
2788
2796
throw new XmlPullParserException ( "entity reference names can not start with character '"
@@ -2811,7 +2819,7 @@ else if ( ch >= 'A' && ch <= 'F' )
2811
2819
text = "<" ;
2812
2820
}
2813
2821
charRefOneCharBuf [0 ] = '<' ;
2814
- return charRefOneCharBuf ;
2822
+ return - 1 ;
2815
2823
// if(paramPC || isParserTokenizing) {
2816
2824
// if(pcEnd >= pc.length) ensurePC();
2817
2825
// pc[pcEnd++] = '<';
@@ -2824,7 +2832,7 @@ else if ( len == 3 && buf[posStart] == 'a' && buf[posStart + 1] == 'm' && buf[po
2824
2832
text = "&" ;
2825
2833
}
2826
2834
charRefOneCharBuf [0 ] = '&' ;
2827
- return charRefOneCharBuf ;
2835
+ return - 1 ;
2828
2836
}
2829
2837
else if ( len == 2 && buf [posStart ] == 'g' && buf [posStart + 1 ] == 't' )
2830
2838
{
@@ -2833,7 +2841,7 @@ else if ( len == 2 && buf[posStart] == 'g' && buf[posStart + 1] == 't' )
2833
2841
text = ">" ;
2834
2842
}
2835
2843
charRefOneCharBuf [0 ] = '>' ;
2836
- return charRefOneCharBuf ;
2844
+ return - 1 ;
2837
2845
}
2838
2846
else if ( len == 4 && buf [posStart ] == 'a' && buf [posStart + 1 ] == 'p' && buf [posStart + 2 ] == 'o'
2839
2847
&& buf [posStart + 3 ] == 's' )
@@ -2843,7 +2851,7 @@ else if ( len == 4 && buf[posStart] == 'a' && buf[posStart + 1] == 'p' && buf[po
2843
2851
text = "'" ;
2844
2852
}
2845
2853
charRefOneCharBuf [0 ] = '\'' ;
2846
- return charRefOneCharBuf ;
2854
+ return - 1 ;
2847
2855
}
2848
2856
else if ( len == 4 && buf [posStart ] == 'q' && buf [posStart + 1 ] == 'u' && buf [posStart + 2 ] == 'o'
2849
2857
&& buf [posStart + 3 ] == 't' )
@@ -2853,20 +2861,51 @@ else if ( len == 4 && buf[posStart] == 'q' && buf[posStart + 1] == 'u' && buf[po
2853
2861
text = "\" " ;
2854
2862
}
2855
2863
charRefOneCharBuf [0 ] = '"' ;
2856
- return charRefOneCharBuf ;
2857
- }
2858
- else
2859
- {
2860
- final char [] result = lookuEntityReplacement ( len );
2861
- if ( result != null )
2862
- {
2863
- return result ;
2864
- }
2864
+ return -1 ;
2865
2865
}
2866
- if ( tokenize )
2867
- text = null ;
2868
- return null ;
2866
+ return len ; // name not found
2867
+ }
2868
+ }
2869
+
2870
+ /**
2871
+ * Parse an entity reference inside the DOCDECL section.
2872
+ *
2873
+ * @throws XmlPullParserException if invalid XML is detected.
2874
+ * @throws IOException if an I/O error is found.
2875
+ */
2876
+ private void parseEntityRefInDocDecl ()
2877
+ throws XmlPullParserException , IOException
2878
+ {
2879
+ final int len = parseCharOrPredefinedEntityRef ();
2880
+ if ( len < 0 )
2881
+ return ;
2882
+ if ( tokenize )
2883
+ text = null ;
2884
+ }
2885
+
2886
+ /**
2887
+ * Parse an entity reference inside a tag or attribute.
2888
+ *
2889
+ * @return the char array with the replaced character entity, the replaced custom entity, or null if no replacement
2890
+ * could be found.
2891
+ * @throws XmlPullParserException if invalid XML is detected.
2892
+ * @throws IOException if an I/O error is found.
2893
+ */
2894
+ private char [] parseEntityRef ()
2895
+ throws XmlPullParserException , IOException
2896
+ {
2897
+ final int len = parseCharOrPredefinedEntityRef ();
2898
+ if ( len < 0 )
2899
+ return charRefOneCharBuf ;
2900
+
2901
+ final char [] result = lookuEntityReplacement ( len );
2902
+ if ( result != null )
2903
+ {
2904
+ return result ;
2869
2905
}
2906
+ if ( tokenize )
2907
+ text = null ;
2908
+ return null ;
2870
2909
}
2871
2910
2872
2911
/**
@@ -2883,8 +2922,6 @@ private static boolean isValidCodePoint( int codePoint )
2883
2922
}
2884
2923
2885
2924
private char [] lookuEntityReplacement ( int entityNameLen )
2886
- throws XmlPullParserException , IOException
2887
-
2888
2925
{
2889
2926
if ( !allStringsInterned )
2890
2927
{
@@ -2977,7 +3014,7 @@ else if (isValidCodePoint( ch ))
2977
3014
}
2978
3015
else
2979
3016
{
2980
- throw new XmlPullParserException ( "Illegal character 0x" + Integer .toHexString ((( int ) ch )) + " found in comment" , this , null );
3017
+ throw new XmlPullParserException ( "Illegal character 0x" + Integer .toHexString ((ch )) + " found in comment" , this , null );
2981
3018
}
2982
3019
if ( normalizeIgnorableWS )
2983
3020
{
@@ -3484,7 +3521,7 @@ else if ( ch == '>' && bracketLevel == 0 )
3484
3521
break ;
3485
3522
else if ( ch == '&' )
3486
3523
{
3487
- extractEntityRef ();
3524
+ extractEntityRefInDocDecl ();
3488
3525
}
3489
3526
if ( normalizeIgnorableWS )
3490
3527
{
@@ -3538,6 +3575,17 @@ else if ( ch == '\n' )
3538
3575
posEnd = pos - 1 ;
3539
3576
}
3540
3577
3578
+ private void extractEntityRefInDocDecl ()
3579
+ throws XmlPullParserException , IOException
3580
+ {
3581
+ // extractEntityRef
3582
+ posEnd = pos - 1 ;
3583
+
3584
+ int prevPosStart = posStart ;
3585
+ parseEntityRefInDocDecl ();
3586
+ posStart = prevPosStart ;
3587
+ }
3588
+
3541
3589
private void extractEntityRef ()
3542
3590
throws XmlPullParserException , IOException
3543
3591
{
0 commit comments