From 3233622edcfb61ce0f3a69a2bd18fe6ff028402b Mon Sep 17 00:00:00 2001 From: Joshua Sled Date: Fri, 31 Mar 2006 00:00:43 +0000 Subject: [PATCH] Tighten the grammar around quoted strings. Test-case fixes. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13717 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 4 ++++ src/app-utils/test/test-exp-parser.c | 7 ++++--- src/calculation/expression_parser.c | 10 +++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index dbccba009c..db87625968 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,10 @@ 2006-03-30 Joshua Sled + * src/calculation/expression_parser.c (primary_exp): + * src/app-utils/test/test-exp-parser.c (test_parser): Tighten the + grammar around quoted strings. Test-case fixes. + * src/calculation/expression_parser.c (primary_exp): * src/app-utils/test/test-exp-parser.c (test_parser): Add basic validation and test-cases for invalid expressions. Bugs#308554, diff --git a/src/app-utils/test/test-exp-parser.c b/src/app-utils/test/test-exp-parser.c index 3b7c9d1efe..0e478a6445 100644 --- a/src/app-utils/test/test-exp-parser.c +++ b/src/app-utils/test/test-exp-parser.c @@ -39,6 +39,7 @@ _add_pass_test (const char *test_name, const char *exp, gnc_numeric result, char tests = g_list_append (tests, node); } + #define add_fail_test(n,e,o) _add_fail_test((n), (e), (o), __FILE__, __LINE__) static void @@ -134,6 +135,7 @@ test_parser (void) add_fail_test ("bad expression", "รง 1", 0); add_fail_test ("bad expression", "1 asdf", 6); add_fail_test ("bad expression", "asdf 1", 6); + add_fail_test ("bad expression", "asdf jkl", 8); add_fail_test ("bad expression", " (5 + 23)/ ", 14); add_fail_test ("bad expression", " ((((5 + 23)/ ", 17); add_fail_test ("divide by zero", " 4 / (1 - 1)", -1); @@ -160,7 +162,7 @@ test_parser (void) "- 42.72 + 13.32 + 15.48 + 23.4 + 115.4", gnc_numeric_create(35897, 100) ); - // This must be defined for the function-parsing to work. + /* This must be defined for the function-parsing to work. */ scm_c_eval_string("(define (gnc:error->string tag args) (define (write-error port) (if (and (list? args) (not (null? args))) (let ((func (car args))) (if func (begin (display \"Function: \" port) (display func port) (display \", \" port) (display tag port) (display \"\n\n\" port))))) (false-if-exception (apply display-error (fluid-ref the-last-stack) port args)) (display-backtrace (fluid-ref the-last-stack) port) (force-output port)) (false-if-exception (call-with-output-string write-error)))"); scm_c_eval_string( "(define (gnc:plus a b) (+ a b))" ); @@ -193,8 +195,7 @@ test_parser (void) add_pass_test( "test_str( \"two\" : 2 )", NULL, gnc_numeric_create( 4, 1 ) ); add_fail_test( "test_str( 3 : \"three\" )", NULL, 23 ); add_pass_test( "test_str( \"asdf\" : 1 )", NULL, gnc_numeric_create( 1, 1 ) ); - // This used to work before the 334811, 308554 fixes... :/ - //add_fail_test( "\"asdf\" + 0", NULL, 0 ); + add_fail_test("\"asdf\" + 0", NULL, 8); scm_c_eval_string( "(define (gnc:blindreturn val) val)" ); add_pass_test( "blindreturn( 123.1 )", NULL, gnc_numeric_create( 1231, 10 ) ); diff --git a/src/calculation/expression_parser.c b/src/calculation/expression_parser.c index 67745b44d9..7980de1fb4 100644 --- a/src/calculation/expression_parser.c +++ b/src/calculation/expression_parser.c @@ -262,7 +262,7 @@ * After parsing the above expressions the variables nni, jk, tyh and * tgh would all be defined. * - * Functiosn are invoked with expressions of the format + * Functions are invoked with expressions of the format * * [_a-zA-Z]( : : ... : ) * @@ -1226,9 +1226,13 @@ primary_exp (parser_env_ptr pe) rslt = get_named_var (pe); break; case STR_TOKEN: - - if (check_expression_grammar_error(pe)) + if (!(pe->Token == ')' + || pe->Token == ARG_TOKEN)) + { + add_token(pe, EOS); + pe->error_code = EXPRESSION_ERROR; return; + } rslt = get_unnamed_var( pe ); rslt->type = VST_STRING;