diff options
| author | Martin Owens <doctormo@gmail.com> | 2014-01-22 19:58:15 +0000 |
|---|---|---|
| committer | Martin Owens <doctormo@gmail.com> | 2014-01-22 19:58:15 +0000 |
| commit | 9a0c54cb8bc9b0bfc0c6af95f4b156fd717179a8 (patch) | |
| tree | 18809c1bfa21ea2ab6e319a3308dc2d3010a3bd7 /src | |
| parent | Improve use tag logic by recording the loaded documents in a list. (diff) | |
| download | inkscape-9a0c54cb8bc9b0bfc0c6af95f4b156fd717179a8.tar.gz inkscape-9a0c54cb8bc9b0bfc0c6af95f4b156fd717179a8.zip | |
Protect against infinate looping of new included hrefs
(bzr r12970)
Diffstat (limited to 'src')
| -rw-r--r-- | src/document.cpp | 10 | ||||
| -rw-r--r-- | src/document.h | 8 | ||||
| -rw-r--r-- | src/extension/implementation/xslt.cpp | 2 | ||||
| -rw-r--r-- | src/uri-references.cpp | 17 |
4 files changed, 24 insertions, 13 deletions
diff --git a/src/document.cpp b/src/document.cpp index 32a025e87..90f35307d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -315,7 +315,8 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, - unsigned int keepalive) + unsigned int keepalive, + SPDocument *parent) { SPDocument *document = new SPDocument(); @@ -326,6 +327,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, document->rdoc = rdoc; document->rroot = rroot; + document->parent_document = parent; if (document->uri){ g_free(document->uri); @@ -474,7 +476,7 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc, * Fetches document from URI, or creates new, if NULL; public document * appears in document list. */ -SPDocument *SPDocument::createNewDoc(gchar const *uri, unsigned int keepalive, bool make_new) +SPDocument *SPDocument::createNewDoc(gchar const *uri, unsigned int keepalive, bool make_new, SPDocument *parent) { SPDocument *doc; Inkscape::XML::Document *rdoc; @@ -519,7 +521,7 @@ SPDocument *SPDocument::createNewDoc(gchar const *uri, unsigned int keepalive, b //# These should be set by now g_assert(name); - doc = createDoc(rdoc, uri, base, name, keepalive); + doc = createDoc(rdoc, uri, base, name, keepalive, parent); g_free(base); g_free(name); @@ -540,7 +542,7 @@ SPDocument *SPDocument::createNewDocFromMem(gchar const *buffer, gint length, un // TODO fixme: destroy document } else { Glib::ustring name = Glib::ustring::compose( _("Memory document %1"), ++doc_mem_count ); - doc = createDoc(rdoc, NULL, NULL, name.c_str(), keepalive); + doc = createDoc(rdoc, NULL, NULL, name.c_str(), keepalive, NULL); } } diff --git a/src/document.h b/src/document.h index e804a4980..06b2b5f6e 100644 --- a/src/document.h +++ b/src/document.h @@ -221,7 +221,8 @@ public: sigc::connection connectResourcesChanged(const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot); void fitToRect(Geom::Rect const &rect, bool with_margins = false); - static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false); + static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, + bool make_new = false, SPDocument *parent=NULL ); static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive); /** @@ -229,8 +230,9 @@ public: */ static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const &p, bool take_insensitive = false); - // ToDo - Merge createDoc with createNewDoc - static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive); + static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, + gchar const *base, gchar const *name, unsigned int keepalive, + SPDocument *parent); SPDocument *doRef(); SPDocument *doUnref(); diff --git a/src/extension/implementation/xslt.cpp b/src/extension/implementation/xslt.cpp index 9dd9c83ee..bcea06cb5 100644 --- a/src/extension/implementation/xslt.cpp +++ b/src/extension/implementation/xslt.cpp @@ -177,7 +177,7 @@ XSLT::open(Inkscape::Extension::Input */*module*/, gchar const *filename) } g_free(s); - SPDocument * doc = SPDocument::createDoc(rdoc, filename, base, name, true); + SPDocument * doc = SPDocument::createDoc(rdoc, filename, base, name, true, NULL); g_free(base); g_free(name); diff --git a/src/uri-references.cpp b/src/uri-references.cpp index adf948c7b..30e832c04 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -64,25 +64,32 @@ void URIReference::attach(const URI &uri) throw(BadURIException) std::string absPath = Glib::build_filename(basePath, std::string( path ) ); path = absPath.c_str(); - // We look at existing children and parents SPDocument *parent = document; SPDocument *original = document; document = NULL; - while(parent != NULL) { + while(parent != NULL && document == NULL) { + // Check myself and any parents int he chain + if(strcmp(parent->getURI(), path)==0) { + document = parent; + break; + } + // Then check children of those. boost::ptr_list<SPDocument>::iterator iter; for (iter = parent->child_documents.begin(); iter != parent->child_documents.end(); ++iter) { - if(strcmp(iter->getURI(), path)==0) + if(strcmp(iter->getURI(), path)==0) { document = &*iter; + break; + } } parent = parent->parent_document; } + // Load a fresh document from the svg source. if(!document) { - document = SPDocument::createNewDoc(path, FALSE); + document = SPDocument::createNewDoc(path, false, false, original); if(document) { - document->parent_document = original; original->child_documents.push_back(document); } else { g_warning("Could not load svg file: %s", path); |
