ossobv / asterisklint

Asterisk PBX configuration syntax checker
GNU General Public License v3.0
61 stars 12 forks source link

asterisk regex causes python errors #47

Closed perkons closed 3 years ago

perkons commented 3 years ago

OpenBSD 6.8 Asterisk 18.1.1

asterisklint dialplan-check extensions.conf produces a python error:

Traceback (most recent call last):
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/config.py", line 186, in __iter__
    self.on_varset(element)
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/dialplan.py", line 600, in on_varset
    dialplanvarset = DialplanVarset.from_varset(varset)
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/dialplan.py", line 507, in from_varset
    pattern = pattern and Pattern(pattern, varset.where) or None
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/pattern.py", line 107, in __init__
    self.values = self.parse(pattern)
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/pattern.py", line 116, in parse
    return tuple([Pattern.IS_A_PATTERN] + cls.parse_pattern(raw[1:]))
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/pattern.py", line 143, in parse_pattern
    range_end = raw.index(0x5d)  # ']'
ValueError: 93 is not in list

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/ugisu/.pyenv/versions/3.8.0/bin/asterisklint", line 34, in <module>
    sys.exit(main(sys.argv[1:], os.environ))
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/main.py", line 178, in main
    return command_module.main(args, envs)
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/mainutil.py", line 35, in __call__
    return self.handle_args(args)
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/commands/dialplan-check.py", line 50, in handle_args
    dialplan = next(iter(parser))
  File "/Users/ugisu/.pyenv/versions/3.8.0/lib/python3.8/site-packages/asterisklint/config.py", line 192, in __iter__
    raise ProgrammingError(str(element.where)) from exc
asterisklint.config.ProgrammingError: An unexpected exception was raised. This is most likely a bug in the asterisklint library. If you can reproduce the problem and file an issue on the bug tracker, that would be nice. Further info: extensions.conf:15

if extensions.conf has this content:

[general]
static=yes
writeprotect=yes
clearglobalvars=no

[globals]

[phones]
exten => _00XX.,1,NoOp(Outgoing call to +${EXTEN:2})
same => n,Set(zeroesExten=+${EXTEN:2})
same => n,Gosub(set-caller-id,s,1)
same => n,Dial(PJSIP/${zeroesExten}@sometrunk)
same => n,Hangup()

exten => _004490[0,1,6].,1,NoOp(Some number ${EXTEN})
same => n,Wait(1)
same => n,Playback(t26/premium-numbers)
same => n,Hangup()

[set-caller-id]
exten => s,1,NoOp(Set caller ID)
same => n,Set(caller_ext=${CALLERID(num)})
same => n,ExecIf($[${REGEX("^2[0-9][0-9]$" ${caller_ext})} = 1]?Set(CALLERID(num)=+441234567890))
same => n,Return()

if we change exten => _004490[0,1,6].,1,NoOp(Some number ${EXTEN}) with exten => _004490(0|1|6).,1,NoOp(Some number ${EXTEN}) there are no errors, but the regex in Asterisk is not working.

wdoekes commented 3 years ago
exten => _004490[0,1,6].,1,NoOp(Some number ${EXTEN})

Also wrong syntax. You should have _004490[016].

But AsteriskLint shouldn't choke on it. So thanks for the report :)

wdoekes commented 3 years ago

(So, it's actually a dupe of #45.)

perkons commented 3 years ago

Yes, that was my point that it should not trow python errors. But, yes, it is a dublicate.

perkons commented 3 years ago

Thanks!