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

List:       kde-commits
Subject:    [kdoctools] /: Encode the URIs which end up in DTD files
From:       Luigi Toscano <luigi.toscano () tiscali ! it>
Date:       2015-02-28 22:02:10
Message-ID: E1YRpSc-00082j-E3 () scm ! kde ! org
[Download RAW message or body]

Git commit 5753a91fa99cc8c95669e00fbdb115b00621c5f0 by Luigi Toscano.
Committed on 28/02/2015 at 22:01.
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.

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

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

http://commits.kde.org/kdoctools/5753a91fa99cc8c95669e00fbdb115b00621c5f0

diff --git a/cmake/uriencode.cmake b/cmake/uriencode.cmake
new file mode 100644
index 0000000..9e33da9
--- /dev/null
+++ b/cmake/uriencode.cmake
@@ -0,0 +1,23 @@
+# Encode an URI according to RFC 2396
+# kdoctools_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(kdoctools_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 5fa82c7..468e450 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,7 @@
 include_directories( ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} )
 =

+include(uriencode)
+kdoctools_encode_uri(${DocBookXML4_DTD_DIR})
 set (_custom_dtd_kdex "customization/dtd/kdedbx45.dtd")
 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
@@ -14,6 +16,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)
+        kdoctools_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