diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-04 20:03:25 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2019-09-04 20:03:25 +0200 |
commit | c9df78f02b66513c6e831d81c3240a715fee7e70 (patch) | |
tree | 1d4db4b982fea5a4525110b3561bb49ad7892474 | |
parent | c12bdb94ecdc44f200a8030dfde4a5ec46053ea6 (diff) | |
download | blogc-c9df78f02b66513c6e831d81c3240a715fee7e70.tar.gz blogc-c9df78f02b66513c6e831d81c3240a715fee7e70.tar.bz2 blogc-c9df78f02b66513c6e831d81c3240a715fee7e70.zip |
blogc: fixed bug that prevented digits in -D arguments
-rw-r--r-- | src/blogc/main.c | 19 | ||||
-rwxr-xr-x | tests/blogc/check_blogc.sh.in | 22 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/blogc/main.c b/src/blogc/main.c index 2f93d18..550aec8 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -236,12 +236,23 @@ main(int argc, char **argv) goto cleanup; } for (size_t j = 0; pieces[0][j] != '\0'; j++) { - if (!((pieces[0][j] >= 'A' && pieces[0][j] <= 'Z') || - pieces[0][j] == '_')) - { + char c = pieces[0][j]; + if (j == 0) { + if (!(c >= 'A' && c <= 'Z')) { + fprintf(stderr, "blogc: error: invalid value " + "for -D (first character in configuration " + "key must be uppercase): %s\n", pieces[0]); + bc_strv_free(pieces); + rv = 1; + goto cleanup; + } + continue; + } + if (!((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_')) { fprintf(stderr, "blogc: error: invalid value " "for -D (configuration key must be uppercase " - "with '_'): %s\n", pieces[0]); + "with '_' and digits after first character): %s\n", + pieces[0]); bc_strv_free(pieces); rv = 1; goto cleanup; diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in index fcd7172..3e0b8d7 100755 --- a/tests/blogc/check_blogc.sh.in +++ b/tests/blogc/check_blogc.sh.in @@ -167,7 +167,7 @@ cat > "${TEMP}/main.tmpl" <<EOF <!DOCTYPE html> <html lang="en"> <head> - <title>{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %}</title> + <title>{% ifdef FOO1 %}{{ FOO1 }} {% endif %}{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %}</title> </head> <body> <a href="{{ BASE_URL }}/"><div class="name">{{ SITE_TITLE }}</div></a>{% block listing_entry %}{{ CONTENT }}{% endblock %} @@ -223,7 +223,7 @@ cat > "${TEMP}/expected-output.html" <<EOF <!DOCTYPE html> <html lang="en"> <head> - <title>Chunda's website</title> + <title>asd Chunda's website</title> </head> <body> <a href="/"><div class="name">Chunda's website</div></a> @@ -261,6 +261,7 @@ ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ -D BASE_URL= \ -D SITE_TITLE="Chunda's website" \ -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -D FOO1="asd" \ -t "${TEMP}/main.tmpl" \ -o "${TEMP}/output.html" \ -l \ @@ -273,6 +274,7 @@ echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} @abs_top_b -D BASE_URL= \ -D SITE_TITLE="Chunda's website" \ -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -D FOO1="asd" \ -t "${TEMP}/main.tmpl" \ -o "${TEMP}/output2.html" \ -l \ @@ -285,6 +287,7 @@ ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ -D BASE_URL= \ -D SITE_TITLE="Chunda's website" \ -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -D FOO1="asd" \ -t "${TEMP}/main.tmpl" \ -l \ "${TEMP}/post1.txt" "${TEMP}/post2.txt" > "${TEMP}/output3.html" @@ -296,6 +299,7 @@ echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} @abs_top_b -D BASE_URL= \ -D SITE_TITLE="Chunda's website" \ -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -D FOO1="asd" \ -t "${TEMP}/main.tmpl" \ -l \ -i > "${TEMP}/output4.html" @@ -472,3 +476,17 @@ ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ "${TEMP}/post1.txt" 2>&1 | tee "${TEMP}/output.txt" || true grep "blogc: error: template: Invalid block type" "${TEMP}/output.txt" + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D 123=a 2>&1 | tee "${TEMP}/output.txt" || true + +grep \ + "blogc: error: invalid value for -D (first character in configuration key must be uppercase): 123" \ + "${TEMP}/output.txt" + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D A1-3=a 2>&1 | tee "${TEMP}/output.txt" || true + +grep \ + "blogc: error: invalid value for -D (configuration key must be uppercase with '_' and digits after first character): A1-3" \ + "${TEMP}/output.txt" |