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

Escape sourceLabel ids when invalid characters are present #3351

Merged
merged 4 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions contribs/gmf/apps/desktop_alt/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ app.AlternativeDesktopController = function($scope, $injector, ngeoFile, gettext
* @export
*/
this.gridMergeTabs = {
'OSM time merged': ['osm_time', 'osm_time2']
'OSM_time_merged': ['osm_time', 'osm_time2']
};

// Allow angular-gettext-tools to collect the strings to translate
/** @type {angularGettext.Catalog} */
const gettextCatalog = $injector.get('gettextCatalog');
gettextCatalog.getString('OSM time merged');
gettextCatalog.getString('OSM_time_merged');
gettextCatalog.getString('Add a theme');
gettextCatalog.getString('Add a sub theme');
gettextCatalog.getString('Add a layer');
Expand Down
17 changes: 14 additions & 3 deletions contribs/gmf/src/directives/displayquerygrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,20 @@ gmf.DisplayquerygridController.prototype.selectTab = function(gridSource) {
* @param {string|number} sourceLabel Id of the source that should be refreshed.
*/
gmf.DisplayquerygridController.prototype.reflowGrid_ = function(sourceLabel) {
// this is a "work-around" to make sure that the grid is rendered correctly.
// when a pane is activated by setting `this.selectedTab`, the class `active`
// is not yet set on the pane. that's why the class is set manually, and
// This escapes the sourceLabel id if there is some unauthorized values.
// Replace the id to be a valid selector. This work-around allows all
// tabs to work if it is not set correctly in the ctrl.mergeTabs array,
// in example: value with spaces, brackets, parentheses, etc.
const toEscape = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\ |]/g;
if (sourceLabel.match(toEscape) !== null) {
const escapedSourceLabel = sourceLabel.replace(toEscape, '_');
this.$element_.find(`div.tab-pane[id='${sourceLabel}']`).attr('id', escapedSourceLabel);
sourceLabel = escapedSourceLabel;
}

// This is a "work-around" to make sure that the grid is rendered correctly.
// When a pane is activated by setting `this.selectedTab`, the class `active`
// is not yet set on the pane. That's why the class is set manually, and
// after the pane is shown (in the next digest loop), the grid table can
// be refreshed.
const activePane = this.$element_.find(`div.tab-pane#${sourceLabel}`);
Expand Down