diff --git a/packages/ember-data/lib/adapters/errors.js b/packages/ember-data/lib/adapters/errors.js index b4ca080242d..c9b9df5ff72 100644 --- a/packages/ember-data/lib/adapters/errors.js +++ b/packages/ember-data/lib/adapters/errors.js @@ -1,6 +1,6 @@ const EmberError = Ember.Error; -const SOURCE_POINTER_REGEXP = /data\/(attributes|relationships)\/(.*)/; +const SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/; /** @class AdapterError @@ -122,7 +122,7 @@ export function errorsHashToArray(errors) { title: 'Invalid Attribute', detail: messages[i], source: { - pointer: `data/attributes/${key}` + pointer: `/data/attributes/${key}` } }); } diff --git a/packages/ember-data/tests/unit/adapter-errors-test.js b/packages/ember-data/tests/unit/adapter-errors-test.js index 396a21353c9..08c1a4c0b17 100644 --- a/packages/ember-data/tests/unit/adapter-errors-test.js +++ b/packages/ember-data/tests/unit/adapter-errors-test.js @@ -33,17 +33,17 @@ var errorsArray = [ { title: 'Invalid Attribute', detail: 'is invalid', - source: { pointer: 'data/attributes/name' } + source: { pointer: '/data/attributes/name' } }, { title: 'Invalid Attribute', detail: 'must be a string', - source: { pointer: 'data/attributes/name' } + source: { pointer: '/data/attributes/name' } }, { title: 'Invalid Attribute', detail: 'must be a number', - source: { pointer: 'data/attributes/age' } + source: { pointer: '/data/attributes/age' } } ]; @@ -57,6 +57,16 @@ test("errorsArrayToHash", function() { deepEqual(result, errorsHash); }); +test("errorsArrayToHash without trailing slash", function() { + var result = DS.errorsArrayToHash([ + { + detail: 'error message', + source: { pointer: 'data/attributes/name' } + } + ]); + deepEqual(result, { name: ['error message'] }); +}); + test("DS.InvalidError will normalize errors hash with deprecation", function() { var error; @@ -68,7 +78,7 @@ test("DS.InvalidError will normalize errors hash with deprecation", function() { { title: 'Invalid Attribute', detail: 'is invalid', - source: { pointer: 'data/attributes/name' } + source: { pointer: '/data/attributes/name' } } ]); });