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

Commit 3621dbc

Browse files
mustelagkalpak
authored andcommitted
fix($resource) add @ support for properties names
Add support for properties that starts with @. This is useful when working with BadgerFish convention. Closes #10533 Closes #11473
1 parent 65bed61 commit 3621dbc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/ngResource/resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var $resourceMinErr = angular.$$minErr('$resource');
55
// Helper functions and regex to lookup a dotted path on an object
66
// stopping at undefined/null. The path must be composed of ASCII
77
// identifiers (just like $parse)
8-
var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$][0-9a-zA-Z_$]*)+$/;
8+
var MEMBER_NAME_REGEX = /^(\.[a-zA-Z_$@][0-9a-zA-Z_$@]*)+$/;
99

1010
function isValidDottedPath(path) {
1111
return (path != null && path !== '' && path !== 'hasOwnProperty' &&

test/ngResource/resourceSpec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe("resource", function() {
4444
expect(isValidDottedPath('1abc')).toBe(false);
4545
expect(isValidDottedPath('.')).toBe(false);
4646
expect(isValidDottedPath('$')).toBe(true);
47+
expect(isValidDottedPath('@')).toBe(true);
4748
expect(isValidDottedPath('a')).toBe(true);
4849
expect(isValidDottedPath('A')).toBe(true);
4950
expect(isValidDottedPath('a1')).toBe(true);
@@ -53,12 +54,14 @@ describe("resource", function() {
5354
expect(isValidDottedPath('$.$')).toBe(true);
5455
expect(isValidDottedPath('.$')).toBe(false);
5556
expect(isValidDottedPath('$.')).toBe(false);
57+
expect(isValidDottedPath('@.')).toBe(false);
58+
expect(isValidDottedPath('.@')).toBe(false);
5659
});
5760
});
5861

5962
describe('lookupDottedPath', function() {
6063
/* global lookupDottedPath: false */
61-
var data = {a: {b: 'foo', c: null}};
64+
var data = {a: {b: 'foo', c: null, '@d':'d-foo'},'@b':'b-foo'};
6265

6366
it('should throw for invalid path', function() {
6467
expect(function() {
@@ -68,9 +71,11 @@ describe("resource", function() {
6871
});
6972

7073
it('should get dotted paths', function() {
71-
expect(lookupDottedPath(data, 'a')).toEqual({b: 'foo', c: null});
74+
expect(lookupDottedPath(data, 'a')).toEqual({b: 'foo', c: null, '@d':'d-foo'});
7275
expect(lookupDottedPath(data, 'a.b')).toBe('foo');
7376
expect(lookupDottedPath(data, 'a.c')).toBeNull();
77+
expect(lookupDottedPath(data, 'a.@d')).toBe('d-foo');
78+
expect(lookupDottedPath(data, '@b')).toBe('b-foo');
7479
});
7580

7681
it('should skip over null/undefined members', function() {

0 commit comments

Comments
 (0)