[436412] backport Bug 428374: [formatting] unknown regions remove inline css text to WTP 3.2.5
diff --git a/bundles/org.eclipse.wst.css.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.css.core/META-INF/MANIFEST.MF
index a47b5ed..68970e3 100644
--- a/bundles/org.eclipse.wst.css.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.css.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.css.core; singleton:=true
-Bundle-Version: 1.1.403.qualifier
+Bundle-Version: 1.1.404.qualifier
Bundle-Activator: org.eclipse.wst.css.core.internal.CSSCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/formatter/AbstractCSSSourceFormatter.java b/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/formatter/AbstractCSSSourceFormatter.java
index 8ceb138..8dc5665 100644
--- a/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/formatter/AbstractCSSSourceFormatter.java
+++ b/bundles/org.eclipse.wst.css.core/src/org/eclipse/wst/css/core/internal/formatter/AbstractCSSSourceFormatter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -487,6 +487,7 @@
*/
protected final void formatChildren(ICSSNode node, StringBuffer source) {
ICSSNode child = node.getFirstChild();
+ ICSSNode last = null;
boolean first = true;
while (child != null) {
// append child
@@ -499,10 +500,34 @@
formatBefore(node, child, new String(childSource), source, null);
}
source.append(childSource);
+ last = child;
// append between children
child = child.getNextSibling();
first = false;
}
+ // This handles the case where the last child doesn't align with the end of the parent node, likely malformed content
+ if (node instanceof IndexedRegion && last instanceof IndexedRegion && (node.getOwnerDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE)) {
+ IndexedRegion parent = (IndexedRegion) node;
+ IndexedRegion lastChild = (IndexedRegion) last;
+ if (lastChild.getEndOffset() < parent.getEndOffset()) {
+ // Find the region at the end offset of the last child
+ IStructuredDocumentRegion region = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(lastChild.getEndOffset());
+ ITextRegionList regions = region != null ? region.getRegions() : null;
+ if (regions != null) {
+ Iterator it = regions.iterator();
+ while (it.hasNext()) {
+ ITextRegion token = (ITextRegion) it.next();
+ if (token.getType() == CSSRegionContexts.CSS_UNKNOWN) {
+ // Found something that won't be consumed. Append the regions that remain in the node to the source
+ do {
+ source.append(region.getFullText());
+ } while ((region = region.getNext()) != null && region.getEndOffset() <= parent.getEndOffset());
+ break;
+ }
+ }
+ }
+ }
+ }
}
/**
diff --git a/features/org.eclipse.wst.web_core.feature.patch/buildnotes_org.eclipse.wst.web_core.feature.patch.html b/features/org.eclipse.wst.web_core.feature.patch/buildnotes_org.eclipse.wst.web_core.feature.patch.html
index 1937c84..bd85441 100644
--- a/features/org.eclipse.wst.web_core.feature.patch/buildnotes_org.eclipse.wst.web_core.feature.patch.html
+++ b/features/org.eclipse.wst.web_core.feature.patch/buildnotes_org.eclipse.wst.web_core.feature.patch.html
@@ -17,5 +17,7 @@
<p>Bug <a href="https://bugs.eclipse.org/368737">368737</a>. Allow adopters to add @Remote and @Local annotations to EJB class when creating a session EJB</p>
<p>Bug <a href="https://bugs.eclipse.org/368749">368749</a>. Allow to change the default package for interfaces when creating new session EJBs</p>
<p>Bug <a href="https://bugs.eclipse.org/371019">371019</a>. Incorrect validation of resource across web projects</p>
+<h3>org.eclipse.wst.css.core</h3>
+<p>Bug <a href="https://bugs.eclipse.org/371019">436412</a>. backport Bug 428374 - [formatting] unknown regions remove inline css text to WTP 3.2.5</p>
</body>
</html>
\ No newline at end of file
diff --git a/features/org.eclipse.wst.web_core.feature.patch/feature.properties b/features/org.eclipse.wst.web_core.feature.patch/feature.properties
index db6eb80..be0b284 100644
--- a/features/org.eclipse.wst.web_core.feature.patch/feature.properties
+++ b/features/org.eclipse.wst.web_core.feature.patch/feature.properties
@@ -31,6 +31,7 @@
Bug https://bugs.eclipse.org/368737 Allow adopters to add @Remote and @Local annotations to EJB class when creating a session EJB\n\
Bug https://bugs.eclipse.org/368749 Allow to change the default package for interfaces when creating new session EJBs\n\
Bug https://bugs.eclipse.org/371019 Incorrect validation of resource across web projects\n\
+Bug https://bugs.eclipse.org/436412 backport Bug 428374 - [formatting] unknown regions remove inline css text to WTP 3.2.5\n\
\n\
# "copyright" property - text of the "Feature Update Copyright"
copyright=\
diff --git a/features/org.eclipse.wst.web_core.feature.patch/feature.xml b/features/org.eclipse.wst.web_core.feature.patch/feature.xml
index 356c220..bcedf2c 100644
--- a/features/org.eclipse.wst.web_core.feature.patch/feature.xml
+++ b/features/org.eclipse.wst.web_core.feature.patch/feature.xml
@@ -33,5 +33,11 @@
install-size="0"
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="org.eclipse.wst.css.core"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
</feature>