summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2012-01-08 10:18:33 +0000
committerJason Woodward2012-01-08 11:51:52 +0000
commitafebb536b69bb7040bee5fc93f84dfeec1bbe904 (patch)
tree0a7304021576b77f504633679952d59407c053a2
parent4ce0ecf5eb98fbb574b956e9c95ace7859edc39b (diff)
downloadslapt-get-afebb536b69bb7040bee5fc93f84dfeec1bbe904.tar.gz
strip whitespace from url before parsing
-rw-r--r--ChangeLog3
-rw-r--r--src/configuration.c19
-rw-r--r--t/test_configuration.c13
3 files changed, 22 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 3aed51d..472024c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
+0.10.2m Jan 08, 2012
+ * strip whitespace from url before parsing from slapt-getrc
+
0.10.2l Oct 08, 2011
* added dep, conflicts, and reverse dep unit tests
* Do not return 1 from slapt_get_pkg_dependencies if no dependency information
diff --git a/src/configuration.c b/src/configuration.c
index e6364d2..a572a84 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -335,33 +335,27 @@ slapt_source_t *slapt_init_source(const char *s)
src = slapt_malloc(sizeof *src);
src->priority = SLAPT_PRIORITY_DEFAULT;
src->disabled = SLAPT_FALSE;
- source_len = strlen(s);
+ source_string = slapt_strip_whitespace (s);
+ source_len = strlen (source_string);
/* parse for :[attr] in the source url */
if ((attribute_regex = slapt_init_regex(SLAPT_SOURCE_ATTRIBUTE_REGEX)) == NULL) {
exit(EXIT_FAILURE);
}
- slapt_execute_regex(attribute_regex,s);
+ slapt_execute_regex(attribute_regex,source_string);
if (attribute_regex->reg_return == 0) {
/* if we find an attribute string, extract it */
- attribute_string = slapt_regex_extract_match(attribute_regex, s, 1);
+ attribute_string = slapt_regex_extract_match(attribute_regex, source_string, 1);
attribute_len = strlen(attribute_string);
- source_string = strndup(s, source_len - attribute_len);
- } else {
- /* otherwise we just dup the const string */
- source_string = strndup(s, source_len);
+ source_len -= attribute_len;
}
slapt_free_regex(attribute_regex);
/* now add a trailing / if not already there */
- source_len = strlen(source_string);
if ( source_string[source_len - 1] == '/' ) {
-
- src->url = strdup(source_string);
-
+ src->url = strndup(source_string, source_len);
} else {
-
src->url = slapt_malloc(sizeof *src->url * (source_len + 2));
src->url[0] = '\0';
@@ -383,7 +377,6 @@ slapt_source_t *slapt_init_source(const char *s)
}
src->url[source_len + 1] = '\0';
-
}
free(source_string);
diff --git a/t/test_configuration.c b/t/test_configuration.c
index 5e233a1..8d4f9f0 100644
--- a/t/test_configuration.c
+++ b/t/test_configuration.c
@@ -84,6 +84,18 @@ START_TEST (test_source_list)
}
END_TEST
+START_TEST (test_source_trimming)
+{
+ slapt_source_t *src1 = slapt_init_source("http://www.test.org/dist ");
+ slapt_source_t *src2 = slapt_init_source("http://www.test.org/dist:PREFERRED ");
+
+ fail_if ( strcmp (src1->url,"http://www.test.org/dist/") != 0);
+ fail_if ( strcmp (src2->url,"http://www.test.org/dist/") != 0);
+
+ slapt_free_source(src1);
+ slapt_free_source(src2);
+}
+END_TEST
@@ -96,6 +108,7 @@ Suite *configuration_test_suite()
tcase_add_test (tc, test_working_dir);
tcase_add_test (tc, test_exclude_list);
tcase_add_test (tc, test_source_list);
+ tcase_add_test (tc, test_source_trimming);
suite_add_tcase (s, tc);
return s;