[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs4support] /: Encode the URIs which end up in DTD files
From:       Luigi Toscano <luigi.toscano () tiscali ! it>
Date:       2015-02-28 22:05:41
Message-ID: E1YRpW1-0002fJ-7Z () scm ! kde ! org
[Download RAW message or body]

Git commit 315e660886ea3809db2139bb2ffc16e915792829 by Luigi Toscano.
Committed on 28/02/2015 at 22:05.
Pushed by ltoscano into branch 'master'.

Encode the URIs which end up in DTD files

The URI need to be encoded, because some valid characters for
filenames are not valid according RFC 2396.
Easy way to trigger the issue: when the path contains spaces,
as it happens on MacOSX builds.

The function is duplicated from the matching functions in kdoctools
because:
- this module will go away in the not far future;
- the function is not generic enough to be used outside (yet)

CHANGELOG: Encode invalid chars in paths used in XML DTDs, avoiding errors
REVIEW: 120649

A  +23   -0    cmake/uriencode.cmake
M  +5    -0    src/CMakeLists.txt

http://commits.kde.org/kdelibs4support/315e660886ea3809db2139bb2ffc16e91579=
2829

diff --git a/cmake/uriencode.cmake b/cmake/uriencode.cmake
new file mode 100644
index 0000000..fde06d3
--- /dev/null
+++ b/cmake/uriencode.cmake
@@ -0,0 +1,23 @@
+# Encode an URI according to RFC 2396
+# kdelibs4support_encode_uri takes a variable name and it encodes
+# its value according to RFC 2396 (minus few reserved characters)
+# overwriting the original value.
+#
+# Copyright (c) 2014 Luigi Toscano, <luigi.toscano@tiscali.it>
+#
+# Redistribution and use is allowed according to the terms of the BSD lice=
nse.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+function(kdelibs4support_encode_uri _original_uri)
+    find_package(Perl REQUIRED)
+    # properly encode the URI
+    string(REPLACE "\"" "\\\"" escaped_uri "${${_original_uri}}")
+    execute_process(COMMAND perl -MURI::Escape -e "print uri_escape_utf8(\=
"${escaped_uri}\", \"^A-Za-z0-9\\-\\._~\\/\");"
+                    OUTPUT_VARIABLE encoded_uri
+                    RESULT_VARIABLE res_encoding
+                    OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if (NOT ${res_encoding} EQUAL 0)
+        message(FATAL_ERROR "Problem while encoding the URI ${${_original_=
uri}}")
+    endif()
+    set(${_original_uri} "${encoded_uri}" PARENT_SCOPE)
+endfunction()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 64a53d8..b662893 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -619,10 +619,13 @@ endif ()
 =

 mark_as_advanced (DocBookXML4_DTD_DIR DocBookXML4_DTD_VERSION)
 =

+include(uriencode)
 set (_custom_dtd_kdex "customization/dtd/kdex.dtd")
 # The path to KDocTools resources is set as absolute, allowing the
 # installation of KDocTools and KDELibs4Support in different prefixes.
 set (_KDocTools_customization_dir "${KDOCTOOLS_CUSTOMIZATION_DIR}")
+kdelibs4support_encode_uri(DocBookXML4_DTD_DIR)
+kdelibs4support_encode_uri(_KDocTools_customization_dir)
 configure_file(${_custom_dtd_kdex}.cmake ${CMAKE_CURRENT_BINARY_DIR}/${_cu=
stom_dtd_kdex} )
 # WARNING: this is due to severe limitations on the windows platform to ke=
ep the dtd relocateable
 # see the .xsl.cmake files for a more verbose explanation below
@@ -636,6 +639,8 @@ else()
     # removed using get_filename_component(... ABSOLUTE)
     install(CODE
         "file(RELATIVE_PATH DocBookXML4_DTD_DIR \"${NORMALIZED_DTD_INSTALL=
_PATH}\" \"${DocBookXML4_DTD_DIR}\")
+        include(${CMAKE_SOURCE_DIR}/cmake/uriencode.cmake)
+        kdelibs4support_encode_uri(DocBookXML4_DTD_DIR)
         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${_custom_dtd_kdex}.cma=
ke ${CMAKE_CURRENT_BINARY_DIR}/${_custom_dtd_kdex}.install)"
     )
     get_filename_component(_custom_dtd_kdex_name ${_custom_dtd_kdex} NAME)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic