This is an automated email from the ASF dual-hosted git repository. atkach pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new ec2c4d8 AMBARI-23596 Ambari web should escape slash in config names ec2c4d8 is described below commit ec2c4d8410e571181930fb6d421ecc0723882057 Author: Andrii Tkach <atk...@apache.org> AuthorDate: Tue Apr 17 15:45:49 2018 +0300 AMBARI-23596 Ambari web should escape slash in config names --- ambari-web/app/mixins/common/configs/configs_saver.js | 8 +++++--- ambari-web/app/utils/string_utils.js | 11 +++++++++++ ambari-web/test/utils/string_utils_test.js | 13 +++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ambari-web/app/mixins/common/configs/configs_saver.js b/ambari-web/app/mixins/common/configs/configs_saver.js index c2245fb..29634c1 100644 --- a/ambari-web/app/mixins/common/configs/configs_saver.js +++ b/ambari-web/app/mixins/common/configs/configs_saver.js @@ -18,6 +18,7 @@ var App = require('app'); var lazyLoading = require('utils/lazy_loading'); +var stringUtils = require('utils/string_utils'); /** * Mixin for saving configs @@ -468,16 +469,17 @@ App.ConfigsSaverMixin = Em.Mixin.create({ properties.forEach(function(property) { if (Em.get(property, 'isRequiredByAgent') !== false) { - desired_config.properties[Em.get(property, 'name')] = this.formatValueBeforeSave(property); + const name = stringUtils.unicodeEscape(Em.get(property, 'name'), /[\/]/g); + desired_config.properties[name] = this.formatValueBeforeSave(property); /** * add is final value */ if (Em.get(property, 'isFinal')) { - attributes.final[Em.get(property, 'name')] = "true"; + attributes.final[name] = "true"; } if (Em.get(property,'propertyType') != null) { Em.get(property,'propertyType').map(function(propType) { - attributes[propType.toLowerCase()][Em.get(property,'name')] = "true"; + attributes[propType.toLowerCase()][name] = "true"; }); } } diff --git a/ambari-web/app/utils/string_utils.js b/ambari-web/app/utils/string_utils.js index 13be1ec..3b5576b 100644 --- a/ambari-web/app/utils/string_utils.js +++ b/ambari-web/app/utils/string_utils.js @@ -255,5 +255,16 @@ module.exports = { return string.split('_').map(function(word) { return word.toLowerCase().capitalize(); }).join(' '); + }, + + /** + * + * @param {string} string + * @param {RegExp} regexp + */ + unicodeEscape: function (string, regexp = /[\s\S]/g) { + return string.replace(regexp, function (escape) { + return '\\u' + ('0000' + escape.charCodeAt().toString(16)).slice(-4); + }); } }; diff --git a/ambari-web/test/utils/string_utils_test.js b/ambari-web/test/utils/string_utils_test.js index 6750906..d1e2ed9 100644 --- a/ambari-web/test/utils/string_utils_test.js +++ b/ambari-web/test/utils/string_utils_test.js @@ -285,4 +285,17 @@ describe('stringUtils', function () { }); }); }); + + describe('#unicodeEscape', function() { + + it('a/b should be converted to "a\\u002fb"', function() { + expect(stringUtils.unicodeEscape('a/b', /[\/]/g)).to.be.equal("a\\u002fb"); + }); + it('a/b should be converted to "\\u0061\\u002f\\u0062"', function() { + expect(stringUtils.unicodeEscape('a/b')).to.be.equal("\\u0061\\u002f\\u0062"); + }); + it('a/b should be converted to "a/b"', function() { + expect(stringUtils.unicodeEscape('a/b', /[0-9]/g)).to.be.equal("a/b"); + }); + }); }); -- To stop receiving notification emails like this one, please contact atk...@apache.org.