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

Escaping quotes in manual variants #7656

Closed
2 tasks done
burner1024 opened this issue May 17, 2022 · 4 comments
Closed
2 tasks done

Escaping quotes in manual variants #7656

burner1024 opened this issue May 17, 2022 · 4 comments
Assignees
Labels
documentation Improvements or additions to the documentation.
Milestone

Comments

@burner1024
Copy link
Contributor

burner1024 commented May 17, 2022

Describe the issue

Trying to mark a variant (through API), it fails because Weblate won't parse JSON with escaped quotes.

Original python object

{'extra_flags': 'variant:Thanx man.. i will finish my job later, because am too tired. Take this shining items which Vic gived me for one kiss. I heard that many things can be buy for such thing called.. "money".'}

converted to json with json.dumps:

data = {"extra_flags": "variant:{}".format(source)}
jdata = json.dumps(data)
{"extra_flags": "variant:Thanx man.. i will finish my job later, because am too tired. Take this shining items which Vic gived me for one kiss. I heard that many things can be buy for such thing called.. \"money\"."}

Then sent to Weblate: requests.patch(url, jdata, headers=HEADERS). Response:

<Response [400]>
{'Date': 'Tue, 17 May 2022 16:41:55 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'vary': 'Accept, Cookie', 'allow': 'GET, PUT, PATCH, DELETE, HEAD, OPTIONS', 'x-ratelimit-limit': '5000', 'x-ratelimit-remaining': '4484', 'x-ratelimit-reset': '2078', 'x-frame-options': 'DENY', 'strict-transport-security': 'max-age=31536000; includeSubDomains; preload', 'x-content-type-options': 'nosniff', 'referrer-policy': 'same-origin', 'cross-origin-opener-policy': 'same-origin', 'CF-Cache-Status': 'DYNAMIC', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=iANvQ8Stcpg2pcm931kF36XtNll62HfITf0GV0mjNHbhrJTdTqPq%2Bw%2B4LWQYSaLemwt%2FyUfDtJcM%2FVpYIAa%2B1Xw2GWF%2FuaV%2BSXXHePpamccsK03TLihFzJq7ZzShIN6leRsr"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare', 'CF-RAY': '70cdcdac2d9e970b-AMS', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'}
{"extra_flags":["Failed to parse flags: Expected end of text, found '\"'  (at char 187), (line:1, col:188)"]}

I already tried

  • I've read and searched the documentation.
  • I've searched for similar issues in this repository.

Steps to reproduce the behavior

  1. Try to add a variant to a string containing quotes.

Expected behavior

Variant flag properly adding.

Screenshots

No response

Exception traceback

No response

How do you run Weblate?

Docker container

Weblate versions

  • Weblate: 4.12.2
  • Django: 4.0.4
  • siphashc: 2.1
  • translate-toolkit: 3.6.2
  • lxml: 4.6.5
  • Pillow: 9.1.0
  • bleach: 5.0.0
  • python-dateutil: 2.8.2
  • social-auth-core: 4.2.0
  • social-auth-app-django: 5.0.0
  • django-crispy-forms: 1.14.0
  • oauthlib: 3.2.0
  • django-compressor: 4.0
  • djangorestframework: 3.13.1
  • django-filter: 21.1
  • django-appconf: 1.0.5
  • user-agents: 2.2.0
  • filelock: 3.6.0
  • jellyfish: 0.9.0
  • openpyxl: 3.0.9
  • celery: 5.2.6
  • kombu: 5.2.4
  • translation-finder: 2.12
  • weblate-language-data: 2022.2
  • html2text: 2020.1.16
  • pycairo: 1.21.0
  • pygobject: 3.42.1
  • diff-match-patch: 20200713
  • requests: 2.27.1
  • django-redis: 5.2.0
  • hiredis: 2.0.0
  • sentry_sdk: 1.5.12
  • Cython: 0.29.28
  • misaka: 2.1.1
  • GitPython: 3.1.27
  • borgbackup: 1.2.0
  • pyparsing: 3.0.9
  • pyahocorasick: 1.4.4
  • python-redis-lock: 3.7.0
  • charset-normalizer: 2.0.12
  • Python: 3.10.4
  • Git: 2.30.2
  • psycopg2: 2.9.3
  • psycopg2-binary: 2.9.3
  • phply: 1.2.5
  • ruamel.yaml: 0.17.21
  • tesserocr: 2.5.2
  • akismet: 1.1
  • boto3: 1.22.11
  • zeep: 4.1.0
  • aeidon: 1.11
  • iniparse: 0.5
  • mysqlclient: 2.1.0
  • Mercurial: 6.1.2
  • git-svn: 2.30.2
  • git-review: 2.3.1
  • Redis server: 6.2.7
  • PostgreSQL server: 14.2
  • Database backends: django.db.backends.postgresql
  • Cache backends: default:RedisCache, avatar:FileBasedCache
  • Email setup: django.core.mail.backends.smtp.EmailBackend: email-smtp.us-east-1.amazonaws.com
  • OS encoding: filesystem=utf-8, default=utf-8
  • Celery: redis://cache:6379/1, redis://cache:6379/1, regular
  • Platform: Linux 4.15.0-176-generic (x86_64)

Weblate deploy checks

No response

Additional context

No response

@nijel
Copy link
Member

nijel commented May 17, 2022

"variant:{}".format(source) is wrong, you need to quote spaces here as well, see https://docs.weblate.org/en/latest/admin/checks.html#customizing-behavior-using-flags.

This is how it is done inside Weblate:

@staticmethod
def format_value(value):
# Regexp objects
if hasattr(value, "pattern"):
value = value.pattern
if " " in value or any(c in value for c in SYNTAXCHARS):
return '"{}"'.format(
value.replace('"', r"\"").replace("\n", "\\n").replace("\r", "\\r")
)
return value

@nijel nijel added the question This is more a question for the support than an issue. label May 17, 2022
@burner1024
Copy link
Contributor Author

Oh, I see, thank you.

@github-actions
Copy link

This issue looks more like a support question than an issue. We strive to answer these reasonably fast, but purchasing the support subscription is not only more responsible and faster for your business but also makes Weblate stronger.

In case your question is already answered, making a donation is the right way to say thank you!

@github-actions
Copy link

The issue you have reported is now resolved. If you don’t feel it’s right, please follow its labels to get a clue for further steps.

  • 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.

@nijel nijel added documentation Improvements or additions to the documentation. and removed question This is more a question for the support than an issue. labels May 18, 2022
@nijel nijel added this to the 4.13 milestone May 18, 2022
@nijel nijel self-assigned this May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to the documentation.
Projects
None yet
Development

No branches or pull requests

2 participants