Migration fails when text to replace includes straight quote

RESOLVED WORKSFORME

Status

defect
RESOLVED WORKSFORME
7 months ago
7 months ago

People

(Reporter: flod, Unassigned)

Tracking

Details

```
            FTL.Message(
                id=FTL.Identifier("page-subtitle"),
                value=REPLACE(
                    "toolkit/chrome/global/aboutSupport.dtd",
                    "aboutSupport.pageSubtitle",
                    {
                        "<a id='supportLink'>": '<a data-l10n-name="support-link">',
                    },
                )
            )
```

This piece of migration fails because of the quote in supportLink. Not sure how to work around it without a fix in the code.

```
Traceback (most recent call last):
  File "/Users/flodolo/github/fluent-migrations/venv/bin/migrate-l10n", line 11, in <module>
    load_entry_point('fluent.migrate', 'console_scripts', 'migrate-l10n')()
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/tool.py", line 143, in cli
    dry_run=args.dry_run
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/tool.py", line 66, in main
    known_legacy_translations
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/context.py", line 393, in serialize_changeset
    changeset, known_translations
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/context.py", line 391, in <dictcomp>
    path: self.fluent_serializer.serialize(snapshot)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/context.py", line 324, in merge_changeset
    self, reference, current, transforms, in_changeset
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/merge.py", line 55, in merge_resource
    body = merge_body(reference.body)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/merge.py", line 24, in merge_body
    for entry in map(merge_entry, body)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/merge.py", line 53, in merge_entry
    return evaluate(ctx, transform)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 80, in evaluate
    return node.traverse(eval_node)
  File "/Users/flodolo/github/fluent-migrations/venv/lib/python2.7/site-packages/fluent/syntax/ast.py", line 72, in traverse
    **{name: visit(value) for name, value in kwargs})
  File "/Users/flodolo/github/fluent-migrations/venv/lib/python2.7/site-packages/fluent/syntax/ast.py", line 72, in <dictcomp>
    **{name: visit(value) for name, value in kwargs})
  File "/Users/flodolo/github/fluent-migrations/venv/lib/python2.7/site-packages/fluent/syntax/ast.py", line 63, in visit
    return value.traverse(fun)
  File "/Users/flodolo/github/fluent-migrations/venv/lib/python2.7/site-packages/fluent/syntax/ast.py", line 74, in traverse
    return fun(node)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 76, in eval_node
    return subnode(ctx)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 366, in __call__
    )(ctx)
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 336, in __call__
    for key, node in replacements:
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 323, in <genexpr>
    for index, key
  File "/Users/flodolo/github/fluent-migrations/venv/fluent-migration/fluent/migrate/transforms.py", line 80, in evaluate
    return node.traverse(eval_node)
AttributeError: 'str' object has no attribute 'traverse'
```
That should be

                    {
                        "<a id='supportLink'>": FTL.TextElement('<a data-l10n-name="support-link">'),
                    },

AFAICT.
(In reply to Axel Hecht [PTO, back Jan 7][:Pike] from comment #1)
> That should be
> 
>                     {
>                         "<a id='supportLink'>": FTL.TextElement('<a
> data-l10n-name="support-link">'),
>                     },
> 
> AFAICT.

This indeed works… But why does this work too?

```
            FTL.Message(
                id=FTL.Identifier("intl-title"),
                value=REPLACE(
                    "toolkit/chrome/global/aboutSupport.dtd",
                    "aboutSupport.intlTitle",
                    {
                        "&amp;": "&",
                    },
                )
            ),
```

Unblocking the other bug in the meantime.
No longer blocks: 1507595
Probably because it's never triggered, 

>>> e.raw_val
u'Internationalization &amp; Localization'
>>> e.val
u'Internationalization & Localization'

We're using .val in context.py, so the &amp; is already resolved.
And I even thought of that, but didn't check. At this point, I think this is a WORKSFORME.
Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.