diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2018-11-06 10:18:22 +0000 |
|---|---|---|
| committer | Thomas Holder <thomas@thomas-holder.de> | 2018-11-07 20:58:07 +0000 |
| commit | 5835eaa282065fe8f44fb071a467f10c0adcb76a (patch) | |
| tree | e9f07e0514b6ccdfaf52619b0a93044cefe19907 /src/xml | |
| parent | Refactor rebase_hrefs with new URI API (diff) | |
| download | inkscape-5835eaa282065fe8f44fb071a467f10c0adcb76a.tar.gz inkscape-5835eaa282065fe8f44fb071a467f10c0adcb76a.zip | |
fix clipboard URL rebasing
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/rebase-hrefs.cpp | 41 | ||||
| -rw-r--r-- | src/xml/rebase-hrefs.h | 2 | ||||
| -rw-r--r-- | src/xml/repr-io.cpp | 10 |
3 files changed, 14 insertions, 39 deletions
diff --git a/src/xml/rebase-hrefs.cpp b/src/xml/rebase-hrefs.cpp index e484ee7a1..c6276a610 100644 --- a/src/xml/rebase-hrefs.cpp +++ b/src/xml/rebase-hrefs.cpp @@ -103,7 +103,12 @@ Inkscape::XML::rebase_href_attrs(gchar const *const old_abs_base, uri = URI::from_native_filename(sp_absref); } - auto new_href = uri.str(URI::from_dirname(new_abs_base).str().c_str()); + std::string baseuri; + if (new_abs_base) { + baseuri = URI::from_dirname(new_abs_base).str(); + } + + auto new_href = uri.str(baseuri.c_str()); ret = cons(AttributeRecord(href_key, share_string(new_href.c_str())), ret); // Check if this is safe/copied or if it is only held. if (sp_absref) { @@ -118,40 +123,6 @@ Inkscape::XML::rebase_href_attrs(gchar const *const old_abs_base, return ret; } -// std::string Inkscape::XML::rebase_href_attrs( std::string const &oldAbsBase, std::string const &newAbsBase, gchar const * /*href*/, gchar const */*absref*/ ) -// { -// std::string ret; -// //g_message( "XX need to flip from [%s] to [%s]", oldAbsBase.c_str(), newAbsBase.c_str() ); - -// if ( oldAbsBase != newAbsBase ) { -// } - -// return ret; -// } - -std::string Inkscape::XML::calc_abs_doc_base(gchar const *doc_base) -{ - /* Note that we don't currently try to handle the case of doc_base containing - * `..' or `.' path components. This non-handling means that sometimes - * sp_relative_path_from_path will needlessly give an absolute path. - * - * It's probably not worth trying to address this until we're using proper - * relative URL/IRI href processing (with liburiparser). - * - * (Note that one possible difficulty with `..' is symlinks.) */ - std::string ret; - - if (!doc_base) { - ret = Glib::get_current_dir(); - } else if (Glib::path_is_absolute(doc_base)) { - ret = doc_base; - } else { - ret = Glib::build_filename( Glib::get_current_dir(), doc_base ); - } - - return ret; -} - void Inkscape::XML::rebase_hrefs(SPDocument *const doc, gchar const *const new_base, bool const spns) { using Inkscape::URI; diff --git a/src/xml/rebase-hrefs.h b/src/xml/rebase-hrefs.h index 79778d537..12e521dea 100644 --- a/src/xml/rebase-hrefs.h +++ b/src/xml/rebase-hrefs.h @@ -8,8 +8,6 @@ class SPDocument; namespace Inkscape { namespace XML { -std::string calc_abs_doc_base(char const *doc_base); - /** * Change relative hrefs in doc to be relative to \a new_base instead of doc.base. * diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index 35a2e3793..258f50fe5 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -43,7 +43,6 @@ using Inkscape::XML::Document; using Inkscape::XML::SimpleDocument; using Inkscape::XML::Node; using Inkscape::XML::AttributeRecord; -using Inkscape::XML::calc_abs_doc_base; using Inkscape::XML::rebase_href_attrs; Document *sp_repr_do_read (xmlDocPtr doc, const gchar *default_ns); @@ -709,8 +708,15 @@ bool sp_repr_save_rebased_file(Document *doc, gchar const *const filename, gchar Glib::ustring old_href_abs_base; Glib::ustring new_href_abs_base; + + if (old_base) { + old_href_abs_base = old_base; + if (!Glib::path_is_absolute(old_href_abs_base)) { + old_href_abs_base = Glib::build_filename(Glib::get_current_dir(), old_href_abs_base); + } + } + if (for_filename) { - old_href_abs_base = calc_abs_doc_base(old_base); if (Glib::path_is_absolute(for_filename)) { new_href_abs_base = Glib::path_get_dirname(for_filename); } else { |
