Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new PHP strings can lead to syntax error #5295

Closed
sentry-io bot opened this issue Jan 30, 2021 · 1 comment · Fixed by translate/translate#4261
Closed

Adding new PHP strings can lead to syntax error #5295

sentry-io bot opened this issue Jan 30, 2021 · 1 comment · Fixed by translate/translate#4261
Assignees
Labels
bug Something is broken.

Comments

@sentry-io
Copy link

sentry-io bot commented Jan 30, 2021

There is currently missing any validation when adding PHP strings. It will happily produce files which are not valid PHP, For example:

<?php
test = 'test';

That in turn causes parse error when trying to load such file:

Sentry Issue: WEBLATE-5HA

SyntaxError: invalid syntax (line 2)
(7 additional frame(s) were not displayed)
...
  File "translate/storage/php.py", line 460, in parse
    tree = parser.parse(phpsrc.decode(self.encoding), lexer=lexer, tracking=True)
  File "ply/yacc.py", line 331, in parse
    return self.parseopt(input, lexer, debug, tracking, tokenfunc)
  File "ply/yacc.py", line 909, in parseopt
    tok = call_errorfunc(self.errorfunc, errtoken, self)
  File "ply/yacc.py", line 192, in call_errorfunc
    r = errorfunc(token)
  File "/home/weblate/weblate-env/lib/python3.7/site-packages/phply/phpparse.py", line 1632, in p_error
    raise SyntaxError('invalid syntax', (None, t.lineno, None, t.value))

FileParseError: invalid syntax (line 2)
(7 additional frame(s) were not displayed)
...
  File "weblate/trans/models/translation.py", line 293, in store
    return self.load_store()
  File "weblate/trans/models/translation.py", line 279, in load_store
    template = self.component.template_store
  File "django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "weblate/trans/models/component.py", line 2719, in template_store
    self.handle_parse_error(error)
  File "weblate/trans/models/component.py", line 1560, in handle_parse_error
    raise FileParseError(error_message)
@github-actions
Copy link

github-actions bot commented Feb 4, 2021

Thank you for your report, the issue you have reported has just been fixed.

  • In case you see a problem with the fix, please comment on this issue.
  • In case you see a similar problem, please open a separate issue.
  • If you are happy with the outcome, don’t hesitate to support Weblate by making a donation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant