Ticket #1236 (new Bug)

Opened 11 months ago

Last modified 6 weeks ago

Unquoted keys in JavaScript objects got compressed by FCKpackager

Reported by: martinkou Owned by:
Priority: Normal Milestone:
Component: Project : FCKpackager Version:
Keywords: Confirmed Cc:

Description

This bug have caused bug #1158 in FCKeditor, which appeared only in the built version.

A test case for the bug can be found below:

	var key1 = "hack";
	var key2 = "and";
	var key3 = "slash";
	var key4 = "rpg";
	var obj = {key1: 'hack', key2: 'and', key3: 'slash', key4: 'rpg'};
	alert( [obj.key1, obj.key2, obj.key3, obj.key4].join(' ')) ;

While the variable identifiers, key1-4 can be compressed to A to D, the object keys of the same names in obj cannot be compressed to A to D as well. However, the FCKpackager's behavior observed from bug #1158 was to compress the above code as follow:

var A="hack";var B="and";var C="slash";var D="rpg";var obj={A:'hack',B:'and',C:'slash',D:'rpg'};alert([obj.key1,obj.key2,obj.key3,obj.key4].join(' '));

Which is incorrect and changed the code's behavior.

Change History

Changed 11 months ago by fredck

We must verify that variable names are not succeeded by a colon.

Changed 6 months ago by w.olchawa

  • keywords Pending WorksForMe added

I've used the current version and the result is:

var key1="hack";var key2="and";var key3="slash";var key4="rpg";var obj={key1:'hack',key2:'and',key3:'slash',key4:'rpg'};alert([obj.key1,obj.key2,obj.key3,obj.key4].join(' '));

Changed 6 weeks ago by fredck

  • keywords Confirmed added; Pending WorksForMe removed

The test case must be inside a function to see the problem:

function()
{
	var key1 = "hack";
	var key2 = "and";
	var key3 = "slash";
	var key4 = "rpg";
	var obj = {key1: 'hack', key2: 'and', key3: 'slash', key4: 'rpg'};
	alert( [obj.key1, obj.key2, obj.key3, obj.key4].join(' ')) ;
}

Results:

function(){var A="hack";var B="and";var C="slash";var D="rpg";var E={A:'hack',B:'and',C:'slash',D:'rpg'};alert([E.key1,E.key2,E.key3,E.key4].join(' '));}
Note: See TracTickets for help on using tickets.