Skip to content

Commit

Permalink
Fix fail when attribute and element have same name
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Jul 11, 2024
1 parent 5bea5e5 commit 5c9d2b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ballerina/tests/fromXml_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -994,18 +994,18 @@ type RecAtt5 record {|
|};

@test:Config {
groups: ["fromXmlString", "testFail"]
groups: ["fromXmlString"]
}
function testXmlStringToRecord38() returns error? {
string xmlStr = string `<Data101 A="name"><A>1</A></Data101>`;
RecAtt3 rec = check parseString(xmlStr);
test:assertEquals(rec.A, "1");

// RecAtt4 rec2 = check parseString(xmlStr);
// test:assertEquals(rec2.A.get("#content"), 1);
RecAtt4 rec2 = check parseString(xmlStr);
test:assertEquals(rec2.A.get("#content"), 1);

// RecAtt5 rec3 = check parseString(xmlStr);
// test:assertEquals(rec3.A, "name");
RecAtt5 rec3 = check parseString(xmlStr);
test:assertEquals(rec3.A, "name");
}

@test:Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,8 @@ private void handleAttributes(XMLStreamReader xmlStreamReader, XmlParserData xml
ATTRIBUTE);
Field field = xmlParserData.attributeHierarchy.peek().remove(attQName);
if (field == null) {
// Here attQName state is set to NOT_DEFINED since it accessed from field hierarchy.
attQName.setAttributeState(NOT_DEFINED);
Optional<Field> f = getFieldFromFieldHierarchy(attQName, xmlParserData);
if (f.isEmpty()) {
continue;
Expand Down

0 comments on commit 5c9d2b2

Please sign in to comment.