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

fix($parse): mark empty expressions as constants and literals #7762

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ function getterFn(path, options, fullExp) {
* service.
*/
function $ParseProvider() {
var cache = {};
var cache = {'': extend(function () {}, {literal: true, constant: true})};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to add an extra code path in the Parser, that will be checked every time an expression is being parsed, so I decided to put it straight in the cache


var $parseOptions = {
csp: false
Expand Down
14 changes: 14 additions & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,13 @@ describe('parser', function() {
});

describe('literal', function() {
it('should mark an empty expressions as literal', inject(function($parse) {
expect($parse('').literal).toBe(true);
expect($parse(' ').literal).toBe(true);
expect($parse('::').literal).toBe(true);
expect($parse(':: ').literal).toBe(true);
}));

it('should mark scalar value expressions as literal', inject(function($parse) {
expect($parse('0').literal).toBe(true);
expect($parse('"hello"').literal).toBe(true);
Expand Down Expand Up @@ -1068,6 +1075,13 @@ describe('parser', function() {
});

describe('constant', function() {
it('should mark an empty expressions as constant', inject(function($parse) {
expect($parse('').constant).toBe(true);
expect($parse(' ').constant).toBe(true);
expect($parse('::').constant).toBe(true);
expect($parse(':: ').constant).toBe(true);
}));

it('should mark scalar value expressions as constant', inject(function($parse) {
expect($parse('12.3').constant).toBe(true);
expect($parse('"string"').constant).toBe(true);
Expand Down