From: DongHun Kwak Date: Mon, 23 Nov 2015 11:19:50 +0000 (+0900) Subject: Sync with tizen 2.4 X-Git-Tag: submit/tizen_3.0_ivi/20161010.000003 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf96f70400096357b015576e18c84e96850958d4;p=platform%2Fupstream%2Flibiri.git Sync with tizen 2.4 Change-Id: I76254d79a90abef9f1e9dda14c6449cac8838cda Signed-off-by: DongHun Kwak --- diff --git a/libiri/parse.c b/libiri/parse.c index 6f4e556..642e4aa 100644 --- a/libiri/parse.c +++ b/libiri/parse.c @@ -18,15 +18,15 @@ * or promote products derived from this software without specific prior * written permission. * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * THIS SOFTWARE IS PROVIDED ``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 * AUTHORS OF THIS SOFTWARE 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 + * 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 + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -76,7 +76,7 @@ static inline const char * iri__copychar_decode(char **dest, const char *src, int convert_space) { unsigned char *p = (unsigned char *) (*dest); - + if(1 == convert_space && '+' == *src) { **dest = ' '; @@ -194,9 +194,9 @@ iri_parse(const char *src) { iri_t *p; char *bufstart, *endp, *bufp, **sl; - const char *at, *colon, *slash, *t; + const char *at, *colon, *slash, *t, *slash3rd; size_t buflen, sc, cp; - + if(NULL == (p = (iri_t *) calloc(1, sizeof(iri_t)))) { return NULL; @@ -216,6 +216,24 @@ iri_parse(const char *src) /* We can disregard the colon if a slash appears before it */ colon = NULL; } + // "@" is valid character in hierarchical part of IRI + if(slash && colon && (colon[1] != '/' || colon[2] != '/')) + { + //if scheme not suffixed with ://, there is not autority + //therefore autority(and user within) is not set + at = NULL; + } + else if(at && slash && slash[1] && slash[2]) + { + slash3rd = strchr(slash + 2, '/'); + //here we know scheme suffix is "://" so autority can exist + //3rd slash should match start of hierarchical part if exists + //@ after that is valid character + if(slash3rd && slash3rd < at) + { + at = NULL; + } + } if(colon && !at) { /* Definitely a scheme */ @@ -438,7 +456,7 @@ iri_parse(const char *src) if(*src == '#') { bufp = ALIGN(bufp); - p->iri.anchor = bufp; + p->iri.anchor = bufp; while(*src) { src = iri__copychar_decode(&bufp, src, 0); @@ -450,7 +468,7 @@ iri_parse(const char *src) { /* Still stuff left? It must be a path... of sorts */ bufp = ALIGN(bufp); - p->iri.path = bufp; + p->iri.path = bufp; while(*src && *src != '?' && *src != '#') { src = iri__copychar_decode(&bufp, src, 0); diff --git a/packaging/libiri.spec b/packaging/libiri.spec index 41bc5a8..2e9da68 100644 --- a/packaging/libiri.spec +++ b/packaging/libiri.spec @@ -1,6 +1,12 @@ +%define run_tests 0 +%if %{run_tests} + # check is defined off at .rpmmacros file. + %undefine check +%endif + Name: libiri Version: 1.1 -Release: 0 +Release: 1 License: BSD-3-Clause Summary: An IRI parsing library Url: http://code.google.com/p/libiri/ @@ -39,6 +45,13 @@ cp %{S:1001} . %reconfigure make %{?_smp_mflags} +%check +%if %{run_tests} + %__make check || exit 0 + chmod +x ./run_test.sh + ./run_test.sh %{name} %{version} +%endif + %install %make_install diff --git a/run_test.sh b/run_test.sh new file mode 100755 index 0000000..c6f1ce4 --- /dev/null +++ b/run_test.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +PACKAGE_NAME=$1 +PACKAGE_VERSION=$2 + +TEST_LOG="/tmp/${PACKAGE_NAME}_test" +export TEST_LOG +rm -f ${TEST_LOG} + +# Color +Color_Off='\e[0m' # Text Reset + +# Regular Colors +Red='\e[0;31m' # Red +Green='\e[0;32m' # Green +Cyan='\e[0;36m' # Cyank + +# Bold +BWhite='\e[1;37m' # White + +result_check() { + result=$? + test_case=$1 + if [ $result -eq 0 ] + then + echo -e "${Green}PASS${Color_Off}: $test_case" + echo "TEST: PASS: $test_case" >> ${TEST_LOG} + else + echo -e "${Red}FAIL${Color_Off}: $test_case" + echo -e "TEST: FAIL: $test_case" >> ${TEST_LOG} + fi +} + +skip_test() { + test_case=$1 + echo -e "${Cyan}SKIP${Color_Off}: $test_case" + echo "TEST: SKIP: $test_case" >> ${TEST_LOG} +} + +run_test() { + test_case=$1 + test_arg=$2 + pushd tests + ./${test_case} ${test_arg} > ${test_case}.ref 2>&1 + diff ${test_case}.ans ${test_case}.ref + result_check "diff ${test_case}.ans ${test_case}.ref" + popd + +} + +run_test_sort() { + test_case=$1 + test_arg=$2 + pushd tests + ./${test_case} ${test_arg} 2>&1 | sort > ${test_case}.ref + diff ${test_case}.ans ${test_case}.ref + result_check "diff ${test_case}.ans ${test_case}.ref" + popd + +} + + run_test iridump "abc://username:password@example.com:123/path/data?key=value#fragid1" + +TOTAL_CNT=`grep "TEST:" ${TEST_LOG} | wc -l` +PASS_CNT=`grep "PASS:" ${TEST_LOG} | wc -l` +FAIL_CNT=`grep "FAIL:" ${TEST_LOG} | wc -l` +SKIP_CNT=`grep "SKIP:" ${TEST_LOG} | wc -l` + + +br='==================='; br=$br$br$br$br; + +echo -e "${Green}$br ${Color_Off}" +echo -e "${Green}Testsuite summary for ${PACKAGE_NAME} ${PACKAGE_VERSION}${Color_Off}" +echo -e "${Green}$br ${Color_Off}" +echo -e "#${BWhite} TOTAL: $TOTAL_CNT ${Color_Off}" +echo -e "#${Green} PASS${Color_Off} : $PASS_CNT" +echo -e "#${Red} FAIL${Color_Off} : $FAIL_CNT" +echo -e "#${Cyan} SKIP${Color_Off} : $SKIP_CNT" +echo -e "${Green}$br ${Color_Off}" + +rm -f ${TEST_LOG} +exit 0 + diff --git a/tests/iridump.ans b/tests/iridump.ans new file mode 100644 index 0000000..c49eb09 --- /dev/null +++ b/tests/iridump.ans @@ -0,0 +1,12 @@ +Colon occurs before at +Found user + scheme: abc + 0: abc + user: username + auth: (null) +password: password + host: example.com + port: 123 + path: /path/data + query: key=value + anchor: #fragid1