mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-12-23 17:33:50 +03:00
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.
This commit is contained in:
parent
52ce0d70f9
commit
32cac377c8
19
parser.c
19
parser.c
@ -79,6 +79,10 @@
|
||||
#define URI_HASH_EMPTY 0xD943A04E
|
||||
#define URI_HASH_XML 0xF0451F02
|
||||
|
||||
#ifndef STDIN_FILENO
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
struct _xmlStartTag {
|
||||
const xmlChar *prefix;
|
||||
const xmlChar *URI;
|
||||
@ -12744,7 +12748,10 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
|
||||
ctxt->recovery = 1;
|
||||
}
|
||||
|
||||
input = xmlNewInputURL(ctxt, filename, NULL, NULL, 0);
|
||||
if ((filename != NULL) && (filename[0] == '-') && (filename[1] == 0))
|
||||
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, NULL, 0);
|
||||
else
|
||||
input = xmlNewInputURL(ctxt, filename, NULL, NULL, 0);
|
||||
|
||||
ret = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
@ -13777,7 +13784,15 @@ xmlReadFile(const char *filename, const char *encoding, int options)
|
||||
|
||||
xmlCtxtUseOptions(ctxt, options);
|
||||
|
||||
input = xmlNewInputURL(ctxt, filename, NULL, encoding, 0);
|
||||
/*
|
||||
* Backward compatibility for users of command line utilities like
|
||||
* xmlstarlet expecting "-" to mean stdin. This is dangerous and
|
||||
* should be removed at some point.
|
||||
*/
|
||||
if ((filename != NULL) && (filename[0] == '-') && (filename[1] == 0))
|
||||
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, encoding, 0);
|
||||
else
|
||||
input = xmlNewInputURL(ctxt, filename, NULL, encoding, 0);
|
||||
|
||||
doc = xmlCtxtParseDocument(ctxt, input);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user