From fc59095ff4fbef396dae30ee7bb8be381a81a058 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 27 Oct 2017 17:38:37 +1300 Subject: [PATCH] Deprecate allowing spaces around = in scripts This was never documented as supported, and leads to a missing argument quietly swallowing the next action rather than using an empty value or giving an error. Reported by Gaurav Arora in https://github.com/xapian/xapian/pull/182 --- xapian-applications/omega/docs/scriptindex.rst | 11 +++++++++++ xapian-applications/omega/omegatest | 26 ++++++++++++++++++++++++++ xapian-applications/omega/scriptindex.cc | 12 ++++++++++++ 3 files changed, 49 insertions(+) diff --git a/xapian-applications/omega/docs/scriptindex.rst b/xapian-applications/omega/docs/scriptindex.rst index cee3bc888..20dfc9bb8 100644 --- a/xapian-applications/omega/docs/scriptindex.rst +++ b/xapian-applications/omega/docs/scriptindex.rst @@ -15,6 +15,17 @@ Here's an example:: ref : field=ref boolean=Q unique=Q type : field=type boolean=XT +Don't put spaces around the ``=`` separating an action and its argument - +current versions allow spaces here (though this was never documented as +supported) but it leads to a missing argument quietly swallowing the next +action rather than using an empty value or giving an error, e.g. this takes +``hash`` as the field name, which is unlikely to be what was intended:: + + url : field= hash boolean=Q unique=Q + +Since 1.4.6 a deprecation warning is emitted for spaces before or after the +``=``. + The actions are: boolean[=PREFIX] diff --git a/xapian-applications/omega/omegatest b/xapian-applications/omega/omegatest index fddd000cd..f9ba7dfb3 100755 --- a/xapian-applications/omega/omegatest +++ b/xapian-applications/omega/omegatest @@ -495,6 +495,32 @@ else failed=`expr $failed + 1` fi +# Test we warn about spaces before and after '='. +# +# This has never been documented as supported, and was deprecated in 1.4.6 +# because it resulted in this quietly using hash as the field name, which is +# probably not what was intended: +# +# url : field= hash boolean=Q unique=Q +printf 'url : field= hash boolean=Q unique=Q' > "$TEST_INDEXSCRIPT" +rm -rf "$TEST_DB" +if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null \ + | grep -q "warning: putting spaces between '=' and the argument is deprecated" ; then + : # OK +else + echo "scriptindex didn't give expected warning for space after '='" + failed=`expr $failed + 1` +fi +printf 'url : field =link' > "$TEST_INDEXSCRIPT" +rm -rf "$TEST_DB" +if $SCRIPTINDEX "$TEST_DB" "$TEST_INDEXSCRIPT" < /dev/null \ + | grep -q "warning: putting spaces between the action and '=' is deprecated" ; then + : # OK +else + echo "scriptindex didn't give expected warning for space before '='" + failed=`expr $failed + 1` +fi + rm "$OMEGA_CONFIG_FILE" "$TEST_INDEXSCRIPT" "$TEST_TEMPLATE" rm -rf "$TEST_DB" if [ "$failed" = 0 ] ; then diff --git a/xapian-applications/omega/scriptindex.cc b/xapian-applications/omega/scriptindex.cc index 1512ce510..92d21156e 100644 --- a/xapian-applications/omega/scriptindex.cc +++ b/xapian-applications/omega/scriptindex.cc @@ -259,9 +259,16 @@ parse_index_script(const string &filename) << ": Unknown index action '" << action << "'" << endl; exit(1); } + auto i_after_action = i; i = find_if(i, s.end(), [](char ch) { return !C_isspace(ch); }); if (i != s.end() && *i == '=') { + if (i != i_after_action) { + cout << filename << ':' << line_no + << ": warning: putting spaces between the action and " + "'=' is deprecated." << endl; + } + if (arg == NO) { cout << filename << ':' << line_no << ": Index action '" << action @@ -270,6 +277,11 @@ parse_index_script(const string &filename) } ++i; j = find_if(i, s.end(), [](char ch) { return !C_isspace(ch); }); + if (i != j) { + cout << filename << ':' << line_no + << ": warning: putting spaces between '=' and the " + "argument is deprecated." << endl; + } i = find_if(j, s.end(), [](char ch) { return C_isspace(ch); }); string val(j, i); if (takes_integer_argument) { -- 2.11.4.GIT