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

Fix for..in when polyfills are used #936

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"url": "git://github.com/marmelab/ng-admin.git"
},
"devDependencies": {
"admin-config": "^0.11.0",
"admin-config": "git://github.com/RichardBradley/admin-config.git#a455071e",
"angular": "~1.3.15",
"angular-bootstrap": "^0.12.0",
"angular-mocks": "1.3.14",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function maExportToCsvButton ($stateParams, Papa, notification, A
.then(referenceData => {
const references = exportView.getReferences();
for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
AdminDescription.getEntryConstructor().createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maButtonField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function maButtonField() {
var a = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
a.setAttribute(name, attributes[name]);
}
scope.toggle = function() {
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maCheckboxField.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function maCheckboxField() {
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
input.setAttribute(name, attributes[name]);
}
},
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maChoiceField.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function maChoiceField($compile) {

var select = element.children()[0];
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
select.setAttribute(name, attributes[name]);
}

Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maChoicesField.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function maChoicesField($compile) {
var select = element.children()[0];

for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
select.setAttribute(name, attributes[name]);
}

Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maDateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function maDateField() {
var input = element.find('input').eq(0);
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
input.attr(name, attributes[name]);
}
scope.toggleDatePicker = function ($event) {
Expand Down
3 changes: 3 additions & 0 deletions src/javascripts/ng-admin/Crud/field/maFileField.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function maFileField(Upload) {
var files = scope.value ? scope.value.split(',') : [];
scope.files = {};
for (var file in files) {
if (!files.hasOwnProperty(file)) continue;
scope.files[files[file]] = {
"name": files[file],
"progress": 0
Expand All @@ -43,6 +44,7 @@ export default function maFileField(Upload) {
var input = element.find('input')[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
input.setAttribute(name, attributes[name]);
}

Expand All @@ -55,6 +57,7 @@ export default function maFileField(Upload) {

scope.files = {};
for (var file in selectedFiles) {
if (!selectedFiles.hasOwnProperty(file)) continue;
uploadParams = angular.copy(scope.field().uploadInformation());
uploadParams.file = selectedFiles[file];
Upload
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maInputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function maInputField() {
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
if (name === 'step') { // allow to use `step` attribute instead of `scope.step`
scope.step = attributes[name];
continue;
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maJsonField.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function maJsonField() {
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
input.setAttribute(name, attributes[name]);
}
scope.$watch('jsonValue', function(jsonValue) {
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/field/maTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default function maTextField() {
var input = element.children()[0];
var attributes = field.attributes();
for (var name in attributes) {
if (!attributes.hasOwnProperty(name)) continue;
input.setAttribute(name, attributes[name]);
}
},
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/list/ListController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class ListController {
this.progression.done();

for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand Down
1 change: 1 addition & 0 deletions src/javascripts/ng-admin/Crud/list/ListLayoutController.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default class ListLayoutController {
field,
i;
for (i in filters) {
if (!filters.hasOwnProperty(i)) continue;
field = filters[i];
fieldName = field.name();
if (this.search[fieldName] === '') {
Expand Down
10 changes: 10 additions & 0 deletions src/javascripts/ng-admin/Crud/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function routing($stateProvider) {
filterEntries: ['dataStore', 'view', 'filterData', function (dataStore, view, filterData) {
const filters = view.getFilterReferences(false);
for (var name in filterData) {
if (!filterData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
filterData[name],
[filters[name].targetField()],
Expand Down Expand Up @@ -107,6 +108,7 @@ function routing($stateProvider) {
referenceEntries: ['dataStore', 'view', 'referenceData', function (dataStore, view, referenceData) {
const references = view.getReferences();
for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand Down Expand Up @@ -174,6 +176,7 @@ function routing($stateProvider) {
referenceEntries: ['dataStore', 'view', 'referenceData', function (dataStore, view, referenceData) {
const references = view.getReferences();
for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand All @@ -188,6 +191,7 @@ function routing($stateProvider) {
referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) {
const referencedLists = view.getReferencedLists();
for (var name in referencedLists) {
if (!referencedLists.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referencedListData[name],
referencedLists[name].targetFields(),
Expand All @@ -213,6 +217,7 @@ function routing($stateProvider) {
Object.keys(referencedLists).map(referencedListName => {
const references = referencedLists[referencedListName].getReferences();
for (var name in references) {
if (!references.hasOwnProperty(name)) continue;
if (!referenceDataForReferencedLists[referencedListName][name]) {
continue;
}
Expand Down Expand Up @@ -269,6 +274,7 @@ function routing($stateProvider) {
choiceEntries: ['dataStore', 'view', 'choiceData', function (dataStore, view, filterData) {
const choices = view.getReferences(false);
for (var name in filterData) {
if (!filterData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
filterData[name],
[choices[name].targetField()],
Expand Down Expand Up @@ -320,6 +326,7 @@ function routing($stateProvider) {
referenceEntries: ['dataStore', 'view', 'referenceData', function (dataStore, view, referenceData) {
const references = view.getReferences();
for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand All @@ -334,6 +341,7 @@ function routing($stateProvider) {
referencedListEntries: ['dataStore', 'view', 'referencedListData', function (dataStore, view, referencedListData) {
const referencedLists = view.getReferencedLists();
for (var name in referencedLists) {
if (!referencedLists.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referencedListData[name],
referencedLists[name].targetFields(),
Expand All @@ -352,6 +360,7 @@ function routing($stateProvider) {
choiceEntries: ['dataStore', 'view', 'choiceData', function (dataStore, view, filterData) {
const choices = view.getReferences(false);
for (var name in filterData) {
if (!filterData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
filterData[name],
[choices[name].targetField()],
Expand All @@ -373,6 +382,7 @@ function routing($stateProvider) {
Object.keys(referencedLists).map(referencedListName => {
const references = referencedLists[referencedListName].getReferences();
for (var name in references) {
if (!references.hasOwnProperty(name)) continue;
if (!referenceDataForReferencedLists[referencedListName][name]) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default function OrderElement() {
objectKey;

for (objectKey in input) {
if (!input.hasOwnProperty(objectKey)) continue;
results.push(input[objectKey]);
}

Expand Down
3 changes: 3 additions & 0 deletions src/javascripts/ng-admin/Main/config/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function routing($stateProvider, $urlRouterProvider) {
collectionName;

for (collectionName in collections) {
if (!collections.hasOwnProperty(collectionName)) continue;
collection = collections[collectionName];
collectionSortField = collection.getSortFieldName();
collectionSortDir = collection.sortDir();
Expand All @@ -77,6 +78,7 @@ function routing($stateProvider, $urlRouterProvider) {
.then(referenceData => {
const references = collection.getReferences();
for (var name in referenceData) {
if (!referenceData.hasOwnProperty(name)) continue;
Entry.createArrayFromRest(
referenceData[name],
[references[name].targetField()],
Expand All @@ -103,6 +105,7 @@ function routing($stateProvider, $urlRouterProvider) {
entries = {};

for (collectionName in responses) {
if (!responses.hasOwnProperty(collectionName)) continue;
entries[collections[collectionName].name()] = responses[collectionName];
}

Expand Down
16 changes: 16 additions & 0 deletions src/javascripts/test/before_all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

if (!Object.prototype.test_prototype_entry) {
Object.prototype.test_prototype_entry =
"Don't use for..in to enumerate Object properties, as users are free to " +
"add entries to the Object prototype, for example for polyfills. " +
"You should instead use\n" +
" for (let i in xs) { if (!xs.hasOwnProperty(i)) continue; var x = xs[i]; ... }";
}

if (!Array.prototype.test_prototype_entry) {
Array.prototype.test_prototype_entry =
"Don't use for..in to enumerate Array properties, as users are free to " +
"add entries to the Array prototype, for example for polyfills. " +
"You should instead use\n" +
" for (let i in xs) { if (!xs.hasOwnProperty(i)) continue; var x = xs[i]; ... }";
}
1 change: 1 addition & 0 deletions src/javascripts/test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = function (config) {

'ng-admin.js',
'test/function.bind.shim.js',
'test/before_all.js',
'test/unit/**/*.js'
],
plugins: ['karma-webpack', 'karma-jasmine', 'karma-chrome-launcher', 'karma-phantomjs-launcher'],
Expand Down