renggli / dart-xml

Lightweight library for parsing, traversing, and transforming XML in Dart.
http://pub.dartlang.org/packages/xml
MIT License
223 stars 52 forks source link

XmlElement.setAttribute can create duplicate attribute if the name contains a colon #156

Closed andrewkolos closed 2 years ago

andrewkolos commented 2 years ago

Appears to be new in 6.2.1.

Issue repro repo. Run the tests using both 6.2.0 and 6.2.1 to see a difference in results.

// passes in 6.2.0
// fails in 6.2.1
test('setting existing attribute that contains a colon in its name - should overwrite attribute', () {
  final bookshelfXml = '''<?xml version="1.0"?>
      <car color:name="blue">
      </car>''';
  final document = XmlDocument.parse(bookshelfXml);
  final carElement = document.rootElement;
  expect(carElement.getAttribute('color:name'), equals('blue'));
  // In 6.2.1, this creates another color:name
  // attribute instead of overwriting the existing one.
  carElement.setAttribute('color:name', 'red');
  expect(carElement.getAttribute('color:name'), equals('red'));
});
renggli commented 2 years ago

Thanks for the bug report, that looks indeed like an issue. Surprised this wasn't caught by existing tests :-/

renggli commented 2 years ago

Thanks again for reporting, added a bunch of more tests.

Generally I am not happy with the way the library handles namespaces, it was added on top of it after the fact and there are various known problems (#136 and #64). I am looking into improving this, but unfortunately this means to make some API breaking changes ...

renggli commented 2 years ago

Updated the release to 6.2.2.