Skip to content

Commit def06f3

Browse files
committed
parser: Selectively reenable reading from "-"
Make filename "-" mean stdin for legacy SAX1 functions and xmlReadFile. This should hopefully fix most command line utilities. See #737.
1 parent e1c7024 commit def06f3

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

parser.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
#define URI_HASH_EMPTY 0xD943A04E
8080
#define URI_HASH_XML 0xF0451F02
8181

82+
#ifndef STDIN_FILENO
83+
#define STDIN_FILENO 0
84+
#endif
85+
8286
struct _xmlStartTag {
8387
const xmlChar *prefix;
8488
const xmlChar *URI;
@@ -12739,7 +12743,10 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
1273912743
ctxt->recovery = 1;
1274012744
}
1274112745

12742-
input = xmlNewInputURL(ctxt, filename, NULL, NULL, 0);
12746+
if ((filename != NULL) && (filename[0] == '-') && (filename[1] == 0))
12747+
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, NULL, 0);
12748+
else
12749+
input = xmlNewInputURL(ctxt, filename, NULL, NULL, 0);
1274312750

1274412751
ret = xmlCtxtParseDocument(ctxt, input);
1274512752

@@ -13761,7 +13768,15 @@ xmlReadFile(const char *filename, const char *encoding, int options)
1376113768

1376213769
xmlCtxtUseOptions(ctxt, options);
1376313770

13764-
input = xmlNewInputURL(ctxt, filename, NULL, encoding, 0);
13771+
/*
13772+
* Backward compatibility for users of command line utilities like
13773+
* xmlstarlet expecting "-" to mean stdin. This is dangerous and
13774+
* should be removed at some point.
13775+
*/
13776+
if ((filename != NULL) && (filename[0] == '-') && (filename[1] == 0))
13777+
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, encoding, 0);
13778+
else
13779+
input = xmlNewInputURL(ctxt, filename, NULL, encoding, 0);
1376513780

1376613781
doc = xmlCtxtParseDocument(ctxt, input);
1376713782

0 commit comments

Comments
 (0)