some work towards fixing JS injection issues

This commit is contained in:
rlx 2012-02-21 12:33:27 +00:00
parent 01d975878b
commit e282a3a9e9
2 changed files with 51 additions and 9 deletions

View file

@ -565,7 +565,7 @@ Ox.ListCalendar = function(options, self) {
event.start = Ox.formatDate(startTime, '%Y-%m-%d %H:%M:%S', true); event.start = Ox.formatDate(startTime, '%Y-%m-%d %H:%M:%S', true);
event.end = Ox.formatDate(endTime, '%Y-%m-%d %H:%M:%S', true); event.end = Ox.formatDate(endTime, '%Y-%m-%d %H:%M:%S', true);
Ox.Log('Calendar', event); Ox.Log('Calendar', event);
self.options.addEvent(event, function(result) { self.options.addEvent(encodeValues(event), function(result) {
if (result.status.code == '200') { if (result.status.code == '200') {
event.id = result.data.id; event.id = result.data.id;
self.options.events.push(event); self.options.events.push(event);
@ -590,7 +590,7 @@ Ox.ListCalendar = function(options, self) {
start: '', end: '' start: '', end: ''
}; };
self.$defineEventButton.options({disabled: true, title: 'Clear Event'}); self.$defineEventButton.options({disabled: true, title: 'Clear Event'});
self.options.editEvent(values, function() { self.options.editEvent(encodeValues(values), function() {
Ox.forEach(values, function(value, key) { Ox.forEach(values, function(value, key) {
self.$list.value(self.options.selected, key, value); self.$list.value(self.options.selected, key, value);
}); });
@ -601,6 +601,16 @@ Ox.ListCalendar = function(options, self) {
}); });
} }
function decodeValues(place) {
return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.decodeHTML(value)
: Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.decodeHTML(value);
})
: value;
});
}
function defineEvent() { function defineEvent() {
var bounds = self.$calendar.getBounds(), var bounds = self.$calendar.getBounds(),
middle = +self.$calendar.options('date'), middle = +self.$calendar.options('date'),
@ -617,12 +627,22 @@ Ox.ListCalendar = function(options, self) {
self.$defineEventButton.options({title: 'Clear Event'}); self.$defineEventButton.options({title: 'Clear Event'});
} }
function encodeValues(place) {
return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.encodeHTML(value)
: Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.encodeHTML(value);
})
: value;
});
}
function editEvent(key, value) { function editEvent(key, value) {
var id = self.selectedEvent, var id = self.selectedEvent,
index = Ox.getIndexById(self.options.events, id), index = Ox.getIndexById(self.options.events, id),
data = {id: id}; data = {id: id};
data[key] = value; data[key] = value;
self.options.editEvent(data, function(result) { self.options.editEvent(encodeValues(data), function(result) {
if (result.status.code == 200) { if (result.status.code == 200) {
self.options.events[index][key] = value; self.options.events[index][key] = value;
self.$list.value(id, key, value); self.$list.value(id, key, value);
@ -728,9 +748,11 @@ Ox.ListCalendar = function(options, self) {
self.$eventName.options({title: event.name || ''}); self.$eventName.options({title: event.name || ''});
self.$eventTitle.show(); self.$eventTitle.show();
if (!isUndefined) { if (!isUndefined) {
self.$eventForm.values(Ox.extend({}, event, { self.$eventForm.values(
decodeValues(Ox.extend({}, event, {
end: event.current ? '' : event.end end: event.current ? '' : event.end
})).show(); }))
).show();
} else { } else {
self.$eventForm.hide(); self.$eventForm.hide();
} }

View file

@ -786,7 +786,7 @@ Ox.ListMap = function(options, self) {
//setStatus(); //setStatus();
} else { } else {
self.$addPlaceButton.options({disabled: true, title: 'Adding...'}); self.$addPlaceButton.options({disabled: true, title: 'Adding...'});
self.options.addPlace(place, function(result) { self.options.addPlace(encodeValues(place), function(result) {
if (result.status.code == 200) { if (result.status.code == 200) {
place.id = result.data.id; place.id = result.data.id;
self.selectedPlace = place.id; self.selectedPlace = place.id;
@ -832,18 +832,38 @@ Ox.ListMap = function(options, self) {
}); });
} }
function decodeValues(place) {
return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.decodeHTML(value)
: Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.decodeHTML(value);
})
: value;
});
}
function definePlace() { function definePlace() {
self.$map.newPlace(); // this will call selectPlace, then editPlace self.$map.newPlace(); // this will call selectPlace, then editPlace
self.$definePlaceButton.options({title: 'Clear Place'}); self.$definePlaceButton.options({title: 'Clear Place'});
} }
function encodeValues(place) {
return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.encodeHTML(value)
: Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.encodeHTML(value);
})
: value;
});
}
function editPlace(keys) { function editPlace(keys) {
Ox.Log('Map', 'EDIT PLACE', keys, self.$placeForm.values()) Ox.Log('Map', 'EDIT PLACE', keys, self.$placeForm.values())
var values = Ox.filter(self.$placeForm.values(), function(values, key) { var values = Ox.filter(self.$placeForm.values(), function(values, key) {
return keys.indexOf(key) > -1; return keys.indexOf(key) > -1;
}); });
values.id = self.selectedPlace; values.id = self.selectedPlace;
self.options.editPlace(values, function(result) { self.options.editPlace(encodeValues(values), function(result) {
Ox.Log('Map', 'EDIT PLACE::', result) Ox.Log('Map', 'EDIT PLACE::', result)
if (result.status.code == 200) { if (result.status.code == 200) {
if ( if (
@ -1055,7 +1075,7 @@ Ox.ListMap = function(options, self) {
function showForm(place) { function showForm(place) {
self.$nameInput.removeClass('OxError'); self.$nameInput.removeClass('OxError');
self.$alternativeNamesInput.setErrors([]); self.$alternativeNamesInput.setErrors([]);
self.$placeForm.values(place).show(); self.$placeForm.values(decodeValues(place)).show();
self.$areaKmInput.value(Ox.formatArea(place.area)).show(); self.$areaKmInput.value(Ox.formatArea(place.area)).show();
} }