8
0
Pārlūkot izejas kodu

Config class does not transform keys in given configuration.

Kamil Piechaczek 9 gadi atpakaļ
vecāks
revīzija
386f53780e

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

@@ -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();
@@ -175,7 +175,7 @@ export default class Config {
 	 */
 	_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();

+ 44 - 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
@@ -157,6 +157,18 @@ describe( 'set', () => {
 		expect( config.get( 'date' ) ).to.be.an.instanceof( Date );
 		expect( config.get( 'instance' ) ).to.be.an.instanceof( SomeClass );
 	} );
+
+	it( 'should not transform keys to lowerCase', () => {
+		config.set( 'Foo', 'Bar' );
+		config.set( 'Example.First', 1 );
+		config.set( 'Example.Second', 2 );
+
+		expect( config.get( 'Foo' ) ).to.equal( 'Bar' );
+		expect( config.get( 'Example' ) ).to.deep.equal( {
+			First: 1,
+			Second: 2
+		} );
+	} );
 } );
 
 describe( 'define', () => {
@@ -169,7 +181,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 +205,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 +221,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 +242,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
@@ -251,6 +263,18 @@ describe( 'define', () => {
 		expect( config.get( 'date' ) ).to.be.an.instanceof( Date );
 		expect( config.get( 'instance' ) ).to.be.an.instanceof( SomeClass );
 	} );
+
+	it( 'should not transform keys to lowerCase', () => {
+		config.set( 'Foo', 'Bar' );
+		config.set( 'Example.First', 1 );
+		config.set( 'Example.Second', 2 );
+
+		expect( config.get( 'Foo' ) ).to.equal( 'Bar' );
+		expect( config.get( 'Example' ) ).to.deep.equal( {
+			First: 1,
+			Second: 2
+		} );
+	} );
 } );
 
 describe( 'get', () => {
@@ -259,7 +283,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 +291,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 +321,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();
 	} );
 } );