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

EOF error when using svg:title tag in component template #31503

Closed
julianess opened this issue Jul 10, 2019 · 6 comments
Closed

EOF error when using svg:title tag in component template #31503

julianess opened this issue Jul 10, 2019 · 6 comments
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser cross-cutting: SVG freq2: medium P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed state: has PR type: bug/fix
Milestone

Comments

@julianess
Copy link

🐞 Bug report

Command

- [ ] new
- [X] build
- [X] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 7.x.x

Description

Using the svg title tag in a different component (using the namespace like svg:title) than the svg root tag component will cause a template parse error. (using title inside a component with svg root tag works fine)
This is working fine:

<!-- demo.component.ts -->
<svg>
    <g>
        <rect x="10" y="10" width="50" height="50">
            <title>I'm a title tag</title>
        </rect>
    </g>
</svg>

While this isn't working:

<!-- demo.component.ts -->
<svg>
    <g svg-title-test></g>
</svg>

<!-- svg-title-test.component.ts -->
<svg:rect x="10" y="10" width="50" height="50">
    <!-- Commenting this line out will show the rect -->
    <svg:title>I'm a title tag</svg:title>
</svg:rect>

🔬 Minimal Reproduction

  1. Creating a new angular app (ng new)
  2. Creating a component with a svg root tag inside
  3. Creating a component with a rect and a title inside the rect (using namespace prefix svg:rect and svg:title)

I've prepared a working example of this issue on stackblitz:
https://stackblitz.com/edit/angular-rqi6k5

🔥 Exception or Error



Error in
node_modules/@angular/compiler@8.0.0/bundles/compiler.umd.js (2479:21)
Template parse errors:
Unexpected character "EOF" ("ommenting this line out will show the rect -->
I'm a title tag
[ERROR ->]"): ng:///AppModule/SvgTitleTestComponent.html@3:11

🌍 Your Environment


Angular CLI: 8.0.1
Node: 10.15.3
OS: win32 x64
Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.800.1
@angular-devkit/core         8.0.1
@angular-devkit/schematics   8.0.1
@schematics/angular          8.0.1
@schematics/update           0.800.1
rxjs                         6.4.0

Anything else relevant?

@mgechev
Copy link
Member

mgechev commented Jul 11, 2019

Seems like this issue belongs to the angular/angular monorepo // cc @alan-agius4

@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Jul 11, 2019
@alan-agius4 alan-agius4 added the area: compiler Issues related to `ngc`, Angular's template compiler label Jul 11, 2019
@ngbot ngbot bot added this to the needsTriage milestone Jul 11, 2019
@alexzuza
Copy link
Contributor

alexzuza commented Jul 11, 2019

Angular tokenizer takes into account only tagName when trying to get the type of a token.

const contentTokenType = this._getTagDefinition(tagName).contentType;

The title tag has predefined mapping

'title': new HtmlTagDefinition({contentType: TagContentType.ESCAPABLE_RAW_TEXT}),

So for svg:title we get TagContentType.ESCAPABLE_RAW_TEXT while it should be TagContentType.PARSABLE_DATA

@PostImpatica
Copy link

Is there any workaround?

@julianess
Copy link
Author

julianess commented Aug 1, 2019

I've searched a lot to get a workaround, but it simply seems to be not possible currently. I've had to comment out those elements in our product to get the compiler work again

@epelaic
Copy link

epelaic commented Sep 25, 2019

Hello,
I just find a workaround.
My svg graphics use svg:*** namespace and svg:title
ex:
<svg:g> <svg:title>My Title</svg:title> </svg:g>
And after upgraded to Angular 8 (from Angular 7.x), il breaks with the same template parse error as above.
After reading this post, I try to remove the svg namespace of the title tag as it will be now parsed like an HTML element and not a SVG element. And it's works (ng serve --aot for now, don't try yet in prod build).

<svg:g> <title>My Title</title> </svg:g>

Thanks alexzuza for the help of finding the code change.

@jelbourn jelbourn added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed severity3: broken labels Oct 1, 2020
crisbeto added a commit to crisbeto/angular that referenced this issue Dec 24, 2020
…le tag

The parser has a list of tag definitions that it uses when parsing the template. Each tag has a
`contentType` which tells the parser what kind of content the tag should contain. The problem is
that the browser has two separate `title` tags (`HTMLTitleElement` and `SVGTitleElement`) and each
of them has to have a different `contentType`, otherwise the parser will throw an error further down
the pipeline.

These changes update the tag definitions so that each tag name can have multiple content types
associated with it and the correct one can be returned based on the element's prefix.

Fixes angular#31503.
crisbeto added a commit to crisbeto/angular that referenced this issue Dec 25, 2020
…le tag

The parser has a list of tag definitions that it uses when parsing the template. Each tag has a
`contentType` which tells the parser what kind of content the tag should contain. The problem is
that the browser has two separate `title` tags (`HTMLTitleElement` and `SVGTitleElement`) and each
of them has to have a different `contentType`, otherwise the parser will throw an error further down
the pipeline.

These changes update the tag definitions so that each tag name can have multiple content types
associated with it and the correct one can be returned based on the element's prefix.

Fixes angular#31503.
crisbeto added a commit to crisbeto/angular that referenced this issue Dec 25, 2020
…le tag

The parser has a list of tag definitions that it uses when parsing the template. Each tag has a
`contentType` which tells the parser what kind of content the tag should contain. The problem is
that the browser has two separate `title` tags (`HTMLTitleElement` and `SVGTitleElement`) and each
of them has to have a different `contentType`, otherwise the parser will throw an error further down
the pipeline.

These changes update the tag definitions so that each tag name can have multiple content types
associated with it and the correct one can be returned based on the element's prefix.

Fixes angular#31503.
@crisbeto crisbeto self-assigned this Dec 26, 2020
atscott pushed a commit that referenced this issue Jan 11, 2021
…le tag (#40259)

The parser has a list of tag definitions that it uses when parsing the template. Each tag has a
`contentType` which tells the parser what kind of content the tag should contain. The problem is
that the browser has two separate `title` tags (`HTMLTitleElement` and `SVGTitleElement`) and each
of them has to have a different `contentType`, otherwise the parser will throw an error further down
the pipeline.

These changes update the tag definitions so that each tag name can have multiple content types
associated with it and the correct one can be returned based on the element's prefix.

Fixes #31503.

PR Close #40259
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler compiler: parser cross-cutting: SVG freq2: medium P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: confirmed state: has PR type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.