Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Possible bug with custom interpolates? #5756

Closed
yellow1912 opened this issue Jan 13, 2014 · 6 comments
Closed

Possible bug with custom interpolates? #5756

yellow1912 opened this issue Jan 13, 2014 · 6 comments

Comments

@yellow1912
Copy link

http://stackoverflow.com/questions/21077607/strange-issue-with-angularjs-template

Quick summary: I'm using custom opening and closing tags for angularjs. For some reason, ng cannot seem to interpret inline template correctly:

Please check this link for working code:
http://plnkr.co/edit/OQiJovrNzOraJdsSXeSY?p=preview

Please check this link for non-working code:
http://plnkr.co/edit/IzGpTdnqmO5MxtldnKec?p=preview

Please note how a random character "a" is added to the template and causes the code to start working.

@caitp
Copy link
Contributor

caitp commented Jan 13, 2014

Weird, it seems to be treating the template as JSON, that's kind of awkward.

I'm not totally sure a fix for this would be admissible, but I think templates should probably not try to parse JSON at all. In the mean time, you could change your custom interpolation markers to not use JSON characters, EG << >> for instance.

caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
The default behaviour causes issues with a wide variety of custom interpolation
markers. Even if the JSON test regexps were strengthened to closer match the
standard JSON format, it would still limit the possibilities of different custom
interpolation markers.

BREAKING CHANGE: $http calls using either the $templateCache, or with custom
Accept headers not including `application/json` will no longer parse JSON.

Closes angular#5756
@caitp
Copy link
Contributor

caitp commented Jan 13, 2014

Hmm, my attempted fix breaks the docs because they're using inline json templates :( I'm not sure of a good way around that.

I guess you might want to look at using different interpolation markers, I'm not sure this is fixable

@yellow1912
Copy link
Author

I will try to use different markers. I think this is very unexpected behavior however, because the content of a template should not be assumed to be in json format.

caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 13, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 14, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
caitp added a commit to caitp/angular.js that referenced this issue Jan 14, 2014
…son'

The default behaviour breaks a wide variety of custom interpolation
markers. Even if the JSON text regexps were strengthened to closer
match the standard JSON format, it would still limit the possibilities
of different custom interpolation markers.

Instead, $http will no longer parse JSON if the response Content-Type header
does not include the term 'json', or if the $templateCache is used. For
inline templates, use the `content-type="json"` attribute to ensure that
inline JSON templates are parsed.

BREAKING CHANGE: Previously, responses would be parsed as JSON if their
content looked vaguely like JSON. Now, they are only parsed as JSON if their
Content-Type response header contains the term 'json', and if they are not
coming from the $templateCache.

Closes angular#5756
Closes angular#2973
@ashleygwilliams ashleygwilliams added this to the 1.3.x milestone Feb 21, 2014
@ashleygwilliams
Copy link

assigning to 1.3.x because the PR is in 1.3.x

@IgorMinar
Copy link
Contributor

oops. I forgot about this fix.

@caitp can you please create a PR that will disable the default transform for requests made by $templateRequest?

@caitp
Copy link
Contributor

caitp commented Oct 14, 2014

Will do

caitp added a commit to caitp/angular.js that referenced this issue Oct 14, 2014
Normally, if there is a Content-Type header with the string "application/json", or else the content
looks sort of JSON-y, $http will attempt to deserialize the JSON into an object. $templateRequest
is intended to request markup, and as such should never attempt to parse JSON, regardless of the
headers or shape of the content.

Closes angular#5756
caitp added a commit to caitp/angular.js that referenced this issue Oct 14, 2014
Normally, if there is a Content-Type header with the string "application/json", or else the content
looks sort of JSON-y, $http will attempt to deserialize the JSON into an object. $templateRequest
is intended to request markup, and as such should never attempt to parse JSON, regardless of the
headers or shape of the content.

Closes angular#5756
@caitp caitp closed this as completed in 1bd473e Oct 17, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.