mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Report (and ignore) failure to load non-existent document. (Credit: Chris Young)
This commit is contained in:
parent
bb3a6bbb3b
commit
ce640e59fd
@ -728,15 +728,18 @@ bool tree_urlfile_load(const char *filename, struct tree *tree,
|
|||||||
dom_document *document;
|
dom_document *document;
|
||||||
dom_node *html, *body, *ul;
|
dom_node *html, *body, *ul;
|
||||||
struct node *root;
|
struct node *root;
|
||||||
|
nserror error;
|
||||||
tree_url_load_ctx ctx;
|
tree_url_load_ctx ctx;
|
||||||
|
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
document = libdom_parse_file(filename, "iso-8859-1");
|
error = libdom_parse_file(filename, "iso-8859-1", &document);
|
||||||
if (document == NULL) {
|
if (error != NSERROR_OK) {
|
||||||
warn_user("TreeLoadError", messages_get("ParsingFail"));
|
if (error != NSERROR_NOT_FOUND) {
|
||||||
|
warn_user("TreeLoadError", messages_get("ParsingFail"));
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ static void ignore_dom_msg(uint32_t severity, void *ctx, const char *msg, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* exported interface documented in libdom.h */
|
/* exported interface documented in libdom.h */
|
||||||
dom_document *libdom_parse_file(const char *filename, const char *encoding)
|
nserror libdom_parse_file(const char *filename, const char *encoding, dom_document **doc)
|
||||||
{
|
{
|
||||||
dom_hubbub_error error;
|
dom_hubbub_error error;
|
||||||
dom_hubbub_parser *parser;
|
dom_hubbub_parser *parser;
|
||||||
@ -270,14 +270,14 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
|
|||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
return NULL;
|
return NSERROR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser = dom_hubbub_parser_create(encoding, false, false,
|
parser = dom_hubbub_parser_create(encoding, false, false,
|
||||||
ignore_dom_msg, NULL, NULL, &document);
|
ignore_dom_msg, NULL, NULL, &document);
|
||||||
if (parser == NULL) {
|
if (parser == NULL) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return NULL;
|
return NSERROR_DOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (feof(fp) == 0) {
|
while (feof(fp) == 0) {
|
||||||
@ -288,7 +288,7 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
|
|||||||
dom_node_unref(document);
|
dom_node_unref(document);
|
||||||
dom_hubbub_parser_destroy(parser);
|
dom_hubbub_parser_destroy(parser);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return NULL;
|
return NSERROR_DOM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,10 +297,11 @@ dom_document *libdom_parse_file(const char *filename, const char *encoding)
|
|||||||
dom_node_unref(document);
|
dom_node_unref(document);
|
||||||
dom_hubbub_parser_destroy(parser);
|
dom_hubbub_parser_destroy(parser);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return NULL;
|
return NSERROR_DOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
dom_hubbub_parser_destroy(parser);
|
dom_hubbub_parser_destroy(parser);
|
||||||
|
|
||||||
return document;
|
*doc = document;
|
||||||
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ typedef bool (*libdom_iterate_cb)(dom_node *node, void *ctx);
|
|||||||
void libdom_iterate_child_elements(dom_node *parent,
|
void libdom_iterate_child_elements(dom_node *parent,
|
||||||
libdom_iterate_cb cb, void *ctx);
|
libdom_iterate_cb cb, void *ctx);
|
||||||
|
|
||||||
dom_document *libdom_parse_file(const char *filename, const char *encoding);
|
nserror libdom_parse_file(const char *filename, const char *encoding,
|
||||||
|
dom_document **doc);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user