Ver código fonte

Merge pull request #45 from ckeditor/t/43

Config class does not transform keys in given configuration.
Piotrek Koszuliński 9 anos atrás
pai
commit
564d665c36

+ 7 - 7
packages/ckeditor5-utils/src/config.js

@@ -67,7 +67,7 @@ export default class Config {
 	 *		config.get( 'toolbar.color' ); // 'red'
 	 *
 	 * @param {String|Object} name The configuration name or an object from which take properties as
-	 * configuration entries. Configuration names are case-insensitive.
+	 * configuration entries. Configuration names are case-sensitive.
 	 * @param {*} value The configuration value. Used if a name is passed.
 	 */
 	set( name, value ) {
@@ -82,7 +82,7 @@ export default class Config {
 	 * rarely used for other needs.
 	 *
 	 * @param {String|Object} name The configuration name or an object from which take properties as
-	 * configuration entries. Configuration names are case-insensitive.
+	 * configuration entries. Configuration names are case-sensitive.
 	 * @param {*} value The configuration value. Used if a name is passed.
 	 */
 	define( name, value ) {
@@ -100,7 +100,7 @@ export default class Config {
 	 *
 	 *		config.get( 'toolbar.collapsed' );
 	 *
-	 * @param {String} name The configuration name. Configuration names are case-insensitive.
+	 * @param {String} name The configuration name. Configuration names are case-sensitive.
 	 * @returns {*} The configuration value or `undefined` if the configuration entry was not found.
 	 */
 	get( name ) {
@@ -113,7 +113,7 @@ export default class Config {
 	 * @private
 	 * @param {Object} target Nested config object.
 	 * @param {String|Object} name The configuration name or an object from which take properties as
-	 * configuration entries. Configuration names are case-insensitive.
+	 * configuration entries. Configuration names are case-sensitive.
 	 * @param {*} value The configuration value. Used if a name is passed.
 	 * @param {Boolean} [isDefine=false] Define if passed configuration should overwrite existing one.
 	 */
@@ -126,7 +126,7 @@ export default class Config {
 		}
 
 		// The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`].
-		const parts = name.toLowerCase().split( '.' );
+		const parts = name.split( '.' );
 
 		// Take the name of the configuration out of the parts. E.g. `resize.width` -> `width`.
 		name = parts.pop();
@@ -170,12 +170,12 @@ export default class Config {
 	 *
 	 * @private
 	 * @param {Object} source level of nested object.
-	 * @param {String} name The configuration name. Configuration names are case-insensitive.
+	 * @param {String} name The configuration name. Configuration names are case-sensitive.
 	 * @returns {*} The configuration value or `undefined` if the configuration entry was not found.
 	 */
 	_getFromSource( source, name ) {
 		// The configuration name should be split into parts if it has dots. E.g. `resize.width` -> [`resize`, `width`].
-		const parts = name.toLowerCase().split( '.' );
+		const parts = name.split( '.' );
 
 		// Take the name of the configuration out of the parts. E.g. `resize.width` -> `width`.
 		name = parts.pop();

+ 20 - 22
packages/ckeditor5-utils/tests/config.js

@@ -29,8 +29,8 @@ describe( 'constructor', () => {
 		expect( config.get( 'creator' ) ).to.equal( 'inline' );
 		expect( config.get( 'language' ) ).to.equal( 'pl' );
 		expect( config.get( 'resize' ) ).to.deep.equal( {
-			minheight: 300,
-			maxheight: 800,
+			minHeight: 300,
+			maxHeight: 800,
 			icon: {
 				path: 'xyz'
 			}
@@ -54,7 +54,7 @@ describe( 'set', () => {
 		} );
 
 		expect( config.get( 'option1' ) ).to.equal( 1 );
-		expect( config.get( 'option2.suboption21' ) ).to.equal( 21 );
+		expect( config.get( 'option2.subOption21' ) ).to.equal( 21 );
 	} );
 
 	it( 'should set configurations when passing name and value', () => {
@@ -115,8 +115,8 @@ describe( 'set', () => {
 		} );
 
 		expect( config.get( 'resize' ) ).to.be.deep.equal( {
-			minheight: 400,		// Overridden
-			maxheight: 800,		// The same
+			minHeight: 400,		// Overridden
+			maxHeight: 800,		// The same
 			hidden: true,		// Expanded
 			icon: {
 				path: 'abc',	// Overridden
@@ -136,8 +136,8 @@ describe( 'set', () => {
 		} );
 
 		expect( config.get( 'resize' ) ).to.deep.equal( {
-			minheight: 400,		// Overridden
-			maxheight: 800,		// The same
+			minHeight: 400,		// Overridden
+			maxHeight: 800,		// The same
 			hidden: true,		// Expanded
 			icon: {
 				path: 'abc',	// Overridden
@@ -169,7 +169,7 @@ describe( 'define', () => {
 		} );
 
 		expect( config.get( 'option1' ) ).to.equal( 1 );
-		expect( config.get( 'option2.suboption21' ) ).to.equal( 21 );
+		expect( config.get( 'option2.subOption21' ) ).to.equal( 21 );
 	} );
 
 	it( 'should set configurations when passing name and value', () => {
@@ -193,7 +193,7 @@ describe( 'define', () => {
 
 		expect( config.get( 'language' ) ).to.equal( 'pl' );
 		expect( config.get( 'resize.icon' ) ).to.be.an( 'object' );
-		expect( config.get( 'resize.minheight' ) ).to.equal( 300 );
+		expect( config.get( 'resize.minHeight' ) ).to.equal( 300 );
 	} );
 
 	it( 'should expand but not override deep configurations', () => {
@@ -209,8 +209,8 @@ describe( 'define', () => {
 		} );
 
 		expect( config.get( 'resize' ) ).to.be.deep.equal( {
-			minheight: 300,		// The same
-			maxheight: 800,		// The same
+			minHeight: 300,		// The same
+			maxHeight: 800,		// The same
 			hidden: true,		// Expanded
 			icon: {
 				path: 'xyz',	// The same
@@ -230,8 +230,8 @@ describe( 'define', () => {
 		} );
 
 		expect( config.get( 'resize' ) ).to.be.deep.equal( {
-			minheight: 300,		// The same
-			maxheight: 800,		// The same
+			minHeight: 300,		// The same
+			maxHeight: 800,		// The same
 			hidden: true,		// Expanded
 			icon: {
 				path: 'xyz',	// The same
@@ -259,7 +259,7 @@ describe( 'get', () => {
 	} );
 
 	it( 'should retrieve a deep configuration', () => {
-		expect( config.get( 'resize.minheight' ) ).to.equal( 300 );
+		expect( config.get( 'resize.minHeight' ) ).to.equal( 300 );
 		expect( config.get( 'resize.icon.path' ) ).to.equal( 'xyz' );
 	} );
 
@@ -267,18 +267,16 @@ describe( 'get', () => {
 		let resize = config.get( 'resize' );
 
 		expect( resize ).to.be.an( 'object' );
-		expect( resize.minheight ).equal( 300 );
-		expect( resize.maxheight ).to.equal( 800 );
+		expect( resize.minHeight ).equal( 300 );
+		expect( resize.maxHeight ).to.equal( 800 );
 		expect( resize.icon ).to.be.an( 'object' );
 
 		expect( resize.icon ).to.be.an( 'object' );
 	} );
 
-	it( 'should retrieve values case-insensitively', () => {
-		expect( config.get( 'Creator' ) ).to.equal( 'inline' );
-		expect( config.get( 'CREATOR' ) ).to.equal( 'inline' );
-		expect( config.get( 'resize.minHeight' ) ).to.equal( 300 );
-		expect( config.get( 'resize.MINHEIGHT' ) ).to.equal( 300 );
+	it( 'should not retrieve values case-insensitively', () => {
+		expect( config.get( 'Creator' ) ).to.be.undefined;
+		expect( config.get( 'resize.MINHEIGHT' ) ).to.be.undefined;
 	} );
 
 	it( 'should return undefined for non existing configuration', () => {
@@ -299,7 +297,7 @@ describe( 'get', () => {
 	it( 'should not be possible to retrieve value directly from config object', () => {
 		expect( config.creator ).to.be.undefined;
 		expect( () => {
-			config.resize.maxheight;
+			config.resize.maxHeight;
 		} ).to.throw();
 	} );
 } );