Projet

Général

Profil

0001-misc-validate-is-varname-.-syntax-13185.patch

Frédéric Péters, 19 septembre 2016 09:03

Télécharger (1,91 ko)

Voir les différences:

Subject: [PATCH 1/2] misc: validate [is varname ...] syntax (#13185)

 tests/test_ezt.py | 12 +++++++++++-
 wcs/qommon/ezt.py |  2 ++
 2 files changed, 13 insertions(+), 1 deletion(-)
tests/test_ezt.py
3 3
from StringIO import StringIO
4 4

  
5 5
from quixote import cleanup
6
from wcs.qommon.ezt import Template, UnclosedBlocksError, UnmatchedEndError, UnmatchedElseError
6
from wcs.qommon.ezt import (Template, UnclosedBlocksError, UnmatchedEndError,
7
        UnmatchedElseError, ArgCountSyntaxError)
7 8
from wcs.scripts import ScriptsSubstitutionProxy
8 9

  
9 10
from utilities import get_app, create_temporary_pub
......
109 110
    except UnmatchedElseError as e:
110 111
        assert e.column == 3 and e.line == 0
111 112

  
113
def test_missing_is_arg():
114
    template = Template()
115
    with pytest.raises(ArgCountSyntaxError):
116
        template.parse('[is foobar][end]')
117
    try:
118
        template.parse('\ntest [is foobar][end]')
119
    except ArgCountSyntaxError as e:
120
        assert e.column == 5 and e.line == 1
121

  
112 122
def test_array_index():
113 123
    template = Template()
114 124
    template.parse('<p>[foo.0]</p>')
wcs/qommon/ezt.py
409 409

  
410 410
          # handle arg2 for the 'is' command
411 411
          if cmd == 'is':
412
            if len(args) != 3:
413
              raise ArgCountSyntaxError(str(args[1:]), line, column)
412 414
            args[2] = _prepare_ref(args[2], for_names, file_args)
413 415
          elif cmd == 'for':
414 416
            for_names.append(args[1][0])  # append the refname
415
-