瀏覽代碼

Merge pull request #324 from ckeditor/i/6219

Internal: Introduced copying default configuration in the `Config` class to make the watchdog feature work correctly. Part of ckeditor/ckeditor5#6219.
Piotrek Koszuliński 5 年之前
父節點
當前提交
4941c915fc
共有 2 個文件被更改,包括 24 次插入2 次删除
  1. 4 2
      packages/ckeditor5-utils/src/config.js
  2. 20 0
      packages/ckeditor5-utils/tests/config.js

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

@@ -30,7 +30,9 @@ export default class Config {
 
 		// Set default configuration.
 		if ( defaultConfigurations ) {
-			this.define( defaultConfigurations );
+			// Clone the configuration to make sure that the properties will not be shared
+			// between editors and make the watchdog feature work correctly.
+			this.define( cloneConfig( defaultConfigurations ) );
 		}
 
 		// Set initial configuration.
@@ -234,7 +236,7 @@ function cloneConfig( source ) {
 	return cloneDeepWith( source, leaveDOMReferences );
 }
 
-// A customizer function for cloneDeepWith.
+// A customized function for cloneDeepWith.
 // It will leave references to DOM Elements instead of cloning them.
 //
 // @param {*} value

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

@@ -6,6 +6,7 @@
 /* global document */
 
 import Config from '../src/config';
+import areConnectedThroughProperties from '../src/areconnectedthroughproperties';
 
 describe( 'Config', () => {
 	let config;
@@ -63,6 +64,25 @@ describe( 'Config', () => {
 			expect( config.get( 'bar' ) ).to.equal( 2 );
 		} );
 
+		it( 'should copy default configuration to not share properties between config instances [watchdog]', () => {
+			const defaultConfig = {
+				foo: 1,
+				bar: [
+					/some regex/,
+					{
+						baz: {}
+					}
+				]
+			};
+
+			const config1 = new Config( {}, defaultConfig );
+			const config2 = new Config( {}, defaultConfig );
+
+			const areStructuresConnected = areConnectedThroughProperties( config1, config2 );
+
+			expect( areStructuresConnected ).to.be.false;
+		} );
+
 		it( 'passed parameters should override default parameters', () => {
 			const defaultConfig = {
 				foo: 1,