uri-encode-1.5.0.6/0000755000000000000000000000000007346545000012104 5ustar0000000000000000uri-encode-1.5.0.6/CHANGELOG.md0000755000000000000000000000033207346545000013716 0ustar0000000000000000#### 1.5.0.6 * Improve performance, thanks to David Farrell #### 1.5.0.5 * Add license field in cabal file #### 1.5.0.4 * Allow utf8-string 1. #### 1.5.0.3 * Use `network-uri` instead of `network` when possible uri-encode-1.5.0.6/LICENSE0000644000000000000000000000272307346545000013115 0ustar0000000000000000Copyright (c) 2011 typLAB All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Universiteit Utrecht nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. uri-encode-1.5.0.6/LICENSE0000755000000000000000000000272307346545000013120 0ustar0000000000000000Copyright (c) 2011 typLAB All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of Universiteit Utrecht nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. uri-encode-1.5.0.6/README.md0000755000000000000000000000124407346545000013367 0ustar0000000000000000# uri-encode [![Build Status](https://travis-ci.org/silkapp/uri-encode.svg?branch=master)](https://travis-ci.org/silkapp/uri-encode) This package allows you to uri encode and uri decode `String`s, `Text`s and `ByteString`s. The default is to encode everything but ASCII alphabetic characters, decimal digits, and `- _ . ~`, according to RFC 3986. It has support for all of unicode, by first encoding strings to UTF8, and then encoding the individual bytes. This works both for `network` \> 2.4 (which also does this) and for older version. Additionally, two command line utilities are provided if the package is built with the `tools` flag: `uri-encode` and `uri-decode`. uri-encode-1.5.0.6/Setup.hs0000644000000000000000000000005607346545000013541 0ustar0000000000000000import Distribution.Simple main = defaultMain uri-encode-1.5.0.6/src/Network/URI/0000755000000000000000000000000007346545000014763 5ustar0000000000000000uri-encode-1.5.0.6/src/Network/URI/Encode.hs0000644000000000000000000001042507346545000016516 0ustar0000000000000000{-# LANGUAGE CPP #-} {- | Unicode aware URI encoding and decoding functions for both String and Text. Although standards are pretty vague about Unicode in URIs most browsers are pretty straightforward when encoding URIs: Encode a text to a UTF-8 string and URI-encode every individual byte (not character). -} module Network.URI.Encode ( encode , encodeWith , encodeText , encodeTextWith , encodeTextToBS , encodeTextToBSWith , encodeByteString , encodeByteStringWith , decode , decodeText , decodeBSToText , decodeByteString , isAllowed ) where import Data.Text import Network.URI import qualified Data.ByteString.Char8 as U import qualified Data.ByteString.UTF8 as U ------------------------------------------------------------------------------- -- | URI encode a 'String', unicode aware. encode :: String -> String encode = encodeWith isAllowed -- | URI encode a 'String', unicode aware, using the predicate to -- decide which characters are escaped ('False' means escape). encodeWith :: (Char -> Bool) -> String -> String encodeWith predicate = escapeURIString predicate . fixUtf8 -- | URI decode a 'String', unicode aware. decode :: String -> String decode = unfixUtf8 . unEscapeString ------------------------------------------------------------------------------- -- | URI encode a 'Text', unicode aware. encodeText :: Text -> Text encodeText = pack . encode . unpack -- | URI encode a 'Text', unicode aware, using the predicate to -- decide which characters are escaped ('False' means escape). encodeTextWith :: (Char -> Bool) -> Text -> Text encodeTextWith predicate = pack . encodeWith predicate . unpack -- | URI decode a 'Text', unicode aware. decodeText :: Text -> Text decodeText = pack . decode . unpack ------------------------------------------------------------------------------- -- | URI encode a 'Text' into a 'ByteString', unicode aware. encodeTextToBS :: Text -> U.ByteString encodeTextToBS = U.pack . encode . unpack -- | URI encode a 'Text' into a 'ByteString', unicode aware, using the -- predicate to decide which characters are escaped ('False' means escape). encodeTextToBSWith :: (Char -> Bool) -> Text -> U.ByteString encodeTextToBSWith predicate = U.pack . encodeWith predicate . unpack -- | URI decode a 'ByteString' into a 'Text', unicode aware. decodeBSToText :: U.ByteString -> Text decodeBSToText = pack . decode . U.unpack ------------------------------------------------------------------------------- -- | URI encode a UTF8-encoded 'ByteString' into a 'ByteString', unicode aware. encodeByteString :: U.ByteString -> U.ByteString encodeByteString = U.pack . encode . U.toString -- | URI encode a UTF8-encoded 'ByteString into a 'ByteString', unicode aware, -- using the predicate to decide which characters are escaped ('False' means -- escape). encodeByteStringWith :: (Char -> Bool) -> U.ByteString -> U.ByteString encodeByteStringWith predicate = U.pack . encodeWith predicate . U.unpack -- | URI decode a 'ByteString' into a UTF8-encoded 'ByteString', unicode aware. decodeByteString :: U.ByteString -> U.ByteString decodeByteString = U.fromString . decode . U.unpack ------------------------------------------------------------------------------- -- | Is a character allowed in a URI. Only ASCII alphabetic -- characters, decimal digits, and - _ . ~ are allowed. This is -- following RFC 3986. isAllowed :: Char -> Bool isAllowed = isUnreserved ------------------------------------------------------------------------------- -- | "Fix" a String before encoding. This actually breaks the string, -- by changing unicode characters into their byte pairs. For network -- \>= 2.4, this is the identity, since that correctly handles unicode -- characters. fixUtf8 :: String -> String #ifdef MIN_VERSION_network #if MIN_VERSION_network(2,4,0) fixUtf8 = id #else fixUtf8 = U.unpack . U.fromString #endif #else fixUtf8 = id #endif -- | "Unfix" a String again. For network \>= 2.4.1.1 this is the -- identity, since that correctly handles unicode characters. Note -- that network 2.4.1.0 (one that is still broken) cannot be excluded -- by CPP, so this version is excluded in the cabal dependencies. unfixUtf8 :: String -> String #ifdef MIN_VERSION_network #if MIN_VERSION_network(2,4,1) unfixUtf8 = id #else unfixUtf8 = U.toString . U.pack #endif #else unfixUtf8 = id #endif uri-encode-1.5.0.6/src/0000755000000000000000000000000007346545000012673 5ustar0000000000000000uri-encode-1.5.0.6/src/URIDecode.hs0000644000000000000000000000042507346545000014773 0ustar0000000000000000module Main where import Data.List (intercalate) import System.Environment (getArgs) import Network.URI.Encode main :: IO () main = getArgs >>= \args -> if null args then interact (unlines . map decode . lines) else putStrLn . intercalate " " . map decode $ args uri-encode-1.5.0.6/src/URIEncode.hs0000644000000000000000000000042607346545000015006 0ustar0000000000000000module Main where import Data.List (intercalate) import System.Environment (getArgs) import Network.URI.Encode main :: IO () main = getArgs >>= \args -> if null args then interact (unlines . map encode . lines) else putStrLn . intercalate " " . map encode $ args uri-encode-1.5.0.6/uri-encode.cabal0000644000000000000000000000416607346545000015131 0ustar0000000000000000name: uri-encode version: 1.5.0.6 description: Unicode aware uri-encoding. synopsis: Unicode aware uri-encoding. cabal-version: >= 1.10 category: Network, Web author: Silk maintainer: code@silk.co license: BSD3 license-file: LICENSE build-type: Simple extra-source-files: CHANGELOG.md LICENSE README.md flag tools description: Build executables default: False manual: True flag network-uri description: Get Network.URI from the network-uri package default: True source-repository head type: git location: https://github.com/silkapp/uri-encode.git library ghc-options: -Wall hs-source-dirs: src exposed-modules: Network.URI.Encode build-depends: base == 4.* , bytestring >= 0.9 && < 0.11 , text >= 0.7 && < 1.3 , utf8-string >= 0.3 && < 1.1 if flag(network-uri) build-depends: network-uri >= 2.6 else build-depends: network (>= 2.2 && < 2.4.1.0) || (> 2.4.1.0 && < 2.6) default-language: Haskell2010 executable uri-encode main-is: URIEncode.hs ghc-options: -Wall hs-source-dirs: src if flag(tools) buildable: True build-depends: base == 4.* , bytestring >= 0.9 && < 0.11 , text >= 0.7 && < 1.3 , utf8-string >= 0.3 && < 1.1 if flag(network-uri) build-depends: network-uri >= 2.6 else build-depends: network (>= 2.2 && < 2.4.1.0) || (> 2.4.1.0 && < 2.6) else buildable: False default-language: Haskell2010 executable uri-decode main-is: URIDecode.hs ghc-options: -Wall hs-source-dirs: src if flag(tools) buildable: True build-depends: base == 4.* , bytestring >= 0.9 && < 0.11 , text >= 0.7 && < 1.3 , utf8-string >= 0.3 && < 1.1 if flag(network-uri) build-depends: network-uri >= 2.6 else build-depends: network (>= 2.2 && < 2.4.1.0) || (> 2.4.1.0 && < 2.6) else buildable: False default-language: Haskell2010