@@ -964,34 +964,17 @@ PHP_METHOD(Dom_HTMLDocument, createFromString)
964
964
RETURN_THROWS ();
965
965
}
966
966
967
- PHP_METHOD (Dom_HTMLDocument , createFromFile )
967
+ static void dom_html_document_create_from_stream (
968
+ zval * return_value ,
969
+ php_stream * stream ,
970
+ zend_long options ,
971
+ const char * override_encoding ,
972
+ size_t override_encoding_len ,
973
+ zend_string * opened_path ,
974
+ const char * filename
975
+ )
968
976
{
969
- const char * filename , * override_encoding = NULL ;
970
977
php_dom_private_data * private_data = NULL ;
971
- size_t filename_len , override_encoding_len ;
972
- zend_long options = 0 ;
973
- php_stream * stream = NULL ;
974
- if (zend_parse_parameters (
975
- ZEND_NUM_ARGS (),
976
- "p|lp!" ,
977
- & filename ,
978
- & filename_len ,
979
- & options ,
980
- & override_encoding ,
981
- & override_encoding_len
982
- ) == FAILURE ) {
983
- RETURN_THROWS ();
984
- }
985
-
986
- /* See php_libxml_streams_IO_open_wrapper(), apparently this caused issues in the past. */
987
- if (strstr (filename , "%00" )) {
988
- zend_argument_value_error (1 , "must not contain percent-encoded NUL bytes" );
989
- RETURN_THROWS ();
990
- }
991
-
992
- if (!check_options_validity (2 , options )) {
993
- RETURN_THROWS ();
994
- }
995
978
996
979
dom_lexbor_libxml2_bridge_application_data application_data ;
997
980
application_data .input_name = filename ;
@@ -1028,15 +1011,6 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1028
1011
dom_setup_parser_encoding_manually ((const lxb_char_t * ) buf , encoding_data , & decoding_encoding_ctx , & application_data );
1029
1012
}
1030
1013
1031
- zend_string * opened_path = NULL ;
1032
- stream = php_stream_open_wrapper_ex (filename , "rb" , REPORT_ERRORS , & opened_path , php_libxml_get_stream_context ());
1033
- if (!stream ) {
1034
- if (!EG (exception )) {
1035
- zend_throw_exception_ex (NULL , 0 , "Cannot open file '%s'" , filename );
1036
- }
1037
- RETURN_THROWS ();
1038
- }
1039
-
1040
1014
/* MIME sniff */
1041
1015
if (should_determine_encoding_implicitly ) {
1042
1016
zend_string * charset = php_libxml_sniff_charset_from_stream (stream );
@@ -1162,12 +1136,6 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1162
1136
lxml_doc -> URL = xmlStrdup ((const xmlChar * ) filename );
1163
1137
}
1164
1138
1165
- if (opened_path != NULL ) {
1166
- zend_string_release_ex (opened_path , false);
1167
- }
1168
- php_stream_close (stream );
1169
- stream = NULL ;
1170
-
1171
1139
dom_object * intern = php_dom_instantiate_object_helper (
1172
1140
return_value ,
1173
1141
dom_html_document_class_entry ,
@@ -1186,10 +1154,52 @@ PHP_METHOD(Dom_HTMLDocument, createFromFile)
1186
1154
php_dom_private_data_destroy (private_data );
1187
1155
}
1188
1156
lxb_html_document_destroy (document );
1189
- php_stream_close (stream );
1157
+ }
1158
+
1159
+ PHP_METHOD (Dom_HTMLDocument , createFromFile )
1160
+ {
1161
+ const char * filename , * override_encoding = NULL ;
1162
+ size_t filename_len , override_encoding_len ;
1163
+ zend_long options = 0 ;
1164
+ if (zend_parse_parameters (
1165
+ ZEND_NUM_ARGS (),
1166
+ "p|lp!" ,
1167
+ & filename ,
1168
+ & filename_len ,
1169
+ & options ,
1170
+ & override_encoding ,
1171
+ & override_encoding_len
1172
+ ) == FAILURE ) {
1173
+ RETURN_THROWS ();
1174
+ }
1175
+
1176
+ /* See php_libxml_streams_IO_open_wrapper(), apparently this caused issues in the past. */
1177
+ if (strstr (filename , "%00" )) {
1178
+ zend_argument_value_error (1 , "must not contain percent-encoded NUL bytes" );
1179
+ RETURN_THROWS ();
1180
+ }
1181
+
1182
+ if (!check_options_validity (2 , options )) {
1183
+ RETURN_THROWS ();
1184
+ }
1185
+
1186
+ zend_string * opened_path = NULL ;
1187
+ php_stream * stream = php_stream_open_wrapper_ex (filename , "rb" , REPORT_ERRORS , & opened_path , php_libxml_get_stream_context ());
1188
+ if (!stream ) {
1189
+ if (!EG (exception )) {
1190
+ zend_throw_exception_ex (NULL , 0 , "Cannot open file '%s'" , filename );
1191
+ }
1192
+ RETURN_THROWS ();
1193
+ }
1194
+
1195
+ dom_html_document_create_from_stream (
1196
+ return_value , stream , options , override_encoding , override_encoding_len , opened_path , filename
1197
+ );
1198
+
1190
1199
if (opened_path != NULL ) {
1191
1200
zend_string_release_ex (opened_path , false);
1192
1201
}
1202
+ php_stream_close (stream );
1193
1203
}
1194
1204
1195
1205
static zend_result dom_write_output_smart_str (void * ctx , const char * buf , size_t size )
0 commit comments