Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 342512

Summary: Plug-in Manifest Editor adds garbage after '&' mnemonics when saving.
Product: [Eclipse Project] PDE Reporter: Masaihko Maedera <maedera>
Component: UIAssignee: Curtis Windatt <curtis.windatt.public>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, daniel_megert, maedera, pwebster
Version: 3.7Flags: daniel_megert: review+
Target Milestone: 3.7 RC1   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 331485    
Bug Blocks: 345165    
Attachments:
Description Flags
bug342512.zip none

Description Masaihko Maedera CLA 2011-04-12 03:28:55 EDT
Build Identifier: I20110407-2200

OS: RedHat Linux Enterprise 6.0
Eclipse SDK
Version: 4.1.0
Build id: I20110407-2200

Plug-in Manifest Editor add garbage after '&' + mnemonics
when it save plugin.xml.
For example.
"Sample Menu(&M)" is changed into "Sample Menu(&M)Menu".
"Sample Action(&S)" is changed into "Sample Action(&S)tion".
Expressions (&M),(&S) are important and popular formats 
for DBCS to use mnemonics 


Reproducible: Always

Steps to Reproduce:
1.Import Project 'bugXXXXX.zip" attached to this report.
2.This project is a plug-in project generated from Template 'Hello, World'.
3.Open 'plugin.xml' with Plug-in Manifest Editor.
4.Click Tab 'Extensions',
5.Verify Menu 'Sample Menu(&M)Menu", Action 'Sample Action(&S)tion'.
6.Those have been already corrupted.
7.Edit them into 'Sample Menu(&M)', 'Sample Action(&S)'.
8.Save the file, but the labels are corrupted again.
Comment 1 Masaihko Maedera CLA 2011-04-12 03:33:39 EDT
Created attachment 193003 [details]
bug342512.zip

I attached a plug-in project to reproduce this bug.
Comment 2 Curtis Windatt CLA 2011-05-06 15:45:27 EDT
Reproduced, very odd behaviour.
Comment 3 Curtis Windatt CLA 2011-05-06 16:34:00 EDT
The problem is that the ReplaceEdit operation is getting the incorrect old value length.  Somewhere (getWritableAttributeNodeValue?) we replace the & with amp;, but when we calculate the length we haven't replaced it yet giving a shorter length.

This manifests in the same way as bug 331485 with each edit replacing the wrong text.  cc'ing Dani so he is aware.

Should be able to fix it by running the replace method on the event's old value.
Comment 4 Curtis Windatt CLA 2011-05-06 16:46:25 EDT
Proposed fix, replace line 233 of XMLInputContext with:

oldLength = getWritableAttributeNodeValue(((String) event.getOldValue())).length();

Inside addAttributeOperation() we just get event.getOldValue() to get the length.  However the event is generated from the model not the xml and the & is translated afterwards.  By translating the old value before checking its length we get the proper result.

I didn't create a patch as it conflicts with the fix on bug 331485 that is waiting to be committed.

Dani, please review this fix for RC1 inclusion.
Comment 5 Dani Megert CLA 2011-05-09 03:57:20 EDT
+1 for the fix for RC1.

However, this exhibits a general problem with the transformation code for special characters: the extension point doc tells the user to use "&amp;" instead of '&' but it doesn't say that '&' inside the PDE editor is good enough (or actually: the only valid form). Now, if the user types "&amp;" as indicated on the help page he will end up with "&amp;amp;". This is with or without the patch and should be handled by a new bug.
Comment 6 Curtis Windatt CLA 2011-05-09 12:11:02 EDT
Fixed in HEAD.

Opened Bug 345165 to improve the character replacement.
Comment 7 Curtis Windatt CLA 2011-05-16 17:37:14 EDT
Verified in I20110514-0800