Skip to content

Commit

Permalink
Issue23 (#66)
Browse files Browse the repository at this point in the history
* Issue 23

* Issue 23
  • Loading branch information
shamblett authored Sep 17, 2024
1 parent 94613ca commit 196630b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/src/xml2json_parker_with_attrs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class _Xml2JsonParkerWithAttrs {
/// Analyze the attribute value in the node
void _parseAttrs(dynamic node, dynamic obj) {
node.attributes.forEach((attr) {
obj!['"_${attr.name.qualified}"'] = '"${attr.value}"';
obj!['"_${_Xml2JsonUtils.escapeTextForJson(attr.name.qualified)}"'] =
'"${_Xml2JsonUtils.escapeTextForJson(attr.value)}"';
});
}

Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
xml: '^6.3.0'
xml: '^6.5.0'

dev_dependencies:
test: '^1.25.0'
lints: '^3.0.0'
build_runner: '^2.4.7'
test: '^1.25.8'
lints: '^4.0.0'
build_runner: '^2.4.12'
build_test: '^2.2.2'
build_web_compilers: '^4.0.7'

Expand Down
1 change: 1 addition & 0 deletions test/issue16_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

@TestOn('vm')
library;

import 'package:xml2json/xml2json.dart';
import 'package:test/test.dart';
Expand Down
14 changes: 14 additions & 0 deletions test/issue23_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@TestOn('vm')
library;

import 'dart:convert';
import 'package:test/test.dart';
Expand Down Expand Up @@ -56,4 +57,17 @@ void main() {
final decoded = json.decode(actual);
expect(decoded['element'], ' "test" ');
}, skip: true);

test(
'xml2json escapes &quot; in the json output when used in an xml attribute - Parker with Attrs',
() {
final xml = '<element att=" &quot;test&quot; "/>';
print(xml);
final actual = (Xml2Json()..parse(xml)).toParkerWithAttrs();
print(actual);
final expected = '{"element": {"_att": " \\"test\\" ", "value": ""}}';
expect(actual, equals(expected));
final decoded = json.decode(actual);
expect(decoded['element'], {'_att': ' "test" ', 'value': ''});
});
}
1 change: 1 addition & 0 deletions test/issue30_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@TestOn('vm')
library;

import 'dart:convert';
import 'dart:io';
Expand Down
1 change: 1 addition & 0 deletions test/issue33_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@TestOn('vm')
library;

import 'dart:convert';
import 'package:test/test.dart';
Expand Down
1 change: 1 addition & 0 deletions test/issue36_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright © 2021年 zjhcsoft. All rights reserved.
*/
@TestOn('vm')
library;

import 'dart:convert';
import 'package:test/test.dart';
Expand Down
1 change: 1 addition & 0 deletions test/issue48_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@TestOn('vm')
library;

import 'package:test/test.dart';
import 'package:xml2json/xml2json.dart';
Expand Down
1 change: 1 addition & 0 deletions test/issue62_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@TestOn('vm')
library;

import 'package:test/test.dart';
import 'package:xml2json/xml2json.dart';
Expand Down

0 comments on commit 196630b

Please sign in to comment.