diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLPositionUtility.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLPositionUtility.java index d45f292cc..5f513706b 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLPositionUtility.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/utils/XMLPositionUtility.java @@ -141,8 +141,9 @@ public static Range selectAttributeValueFromGivenValue(String attrValue, int off DOMNode element = document.findNodeAt(offset); if (element != null && element.hasAttributes()) { List attribues = element.getAttributeNodes(); - for (DOMAttr attr : attribues) { - if (attrValue.equals(attr.getValue())) { + for (int i = attribues.size() - 1; i >= 0; i--) { + DOMAttr attr = attribues.get(i); + if (offset > attr.getStart() && attrValue.equals(attr.getValue())) { return createAttrValueRange(attr, document); } } @@ -1151,17 +1152,17 @@ public static Position getMatchingTagPosition(DOMDocument xmlDocument, Position /** * Select the value from the start/end node without quote. - * + * * For the given attr value: - * + * *

* *

- * + * * it will return range without ". - * + * * @param node the DOM node. - * + * * @return the value from the start/end node without quote. */ public static Range selectValueWithoutQuote(DOMRange node) { @@ -1169,4 +1170,4 @@ public static Range selectValueWithoutQuote(DOMRange node) { return createRange(node.getStart() + 1, node.getEnd() - 1, document); } -} \ No newline at end of file +} diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java index 68ea310eb..364db9046 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaDiagnosticsTest.java @@ -509,6 +509,19 @@ public void cvc_datatype_valid_1_2_3Empty() throws Exception { d(1, 1, 1, 10, XMLSchemaErrorCode.cvc_type_3_1_3)); } + @Test + public void cvc_minLength() throws Exception { + // See issue https://github.com/redhat-developer/vscode-xml/issues/524 + String xml = "\r\n" + + "\r\n" + + "\r\n" + + " \r\n" + + ""; + testDiagnosticsFor(xml, // + d(3, 47, 3, 49, XMLSchemaErrorCode.cvc_minlength_valid), + d(3, 47, 3, 49, XMLSchemaErrorCode.cvc_attribute_3)); + } + @Test public void cvc_maxLength_validOnAttribute() throws Exception { String xml = "\r\n" + // diff --git a/org.eclipse.lemminx/src/test/resources/xsd/minLength.xsd b/org.eclipse.lemminx/src/test/resources/xsd/minLength.xsd new file mode 100644 index 000000000..6405f315d --- /dev/null +++ b/org.eclipse.lemminx/src/test/resources/xsd/minLength.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +