Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
38 changes: 38 additions & 0 deletions .changeset/selfish-laws-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
"cruftless": major
---

Drop pattern matching approach causing parsing issues

Before, there used to be a mechanism that would allow you to have the same
element multiple times within the same template. Only if there would be an
_exact_ match with the elements attributes, it would be considered to be decoded
based on whatever the template was suggesting.

```xml
<foo>
<bar a="1">{first}</bar>
<bar a="2">{second}</bar>
</foo>
```

Given this template and a file like this:

```xml
<foo>
<bar a="2">yay</bar>
</foo>
```

… the resulting data object would be this:

```json
{
"second": "yay"
}
```

It turned out that this was actually causing parsing issues in case the XML
serializer decided to introduce namespaces on an element that didn't have a
namespace before. Since the mechanism was never in use — as far as I can tell
— I decided to drop it.
File renamed without changes.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cruftless",
"version": "0.5.3",
"version": "0.5.4",
"description": "Yet another simple way to parse and generate XML",
"main": "lib/cruftless.js",
"types": "./cruftless.d.ts",
Expand All @@ -25,6 +25,7 @@
"preset": "jest-preset-coffeescript"
},
"devDependencies": {
"@changesets/cli": "^2.26.1",
"coffeescript": "^2.4.1",
"jest": "^24.9.0",
"jest-preset-coffeescript": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion src/model/element.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module.exports = ({types, format = _.identity}) -> (name) ->
matches: (elem) ->
elem.nodeType is 1 and elem.localName is meta.name and (
not(meta.ns?) or meta.ns is elem.namespaceURI
) and (elem.attributes.length is meta.attrs.length) and _.every meta.attrs, (attr) -> attr.definedOn(elem)
)

extract: (elem, target = {}, raw = false) ->
scope = meta.scope(target)
Expand Down
15 changes: 15 additions & 0 deletions test/model/builder-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ describe 'the builder', ->
</NMIStandingData>
</CATSChangeRequest>''')
expect(data).toEqual { changeReasonCode: '1', nmiStandingData: { nmi: '123456789', nmiChecksum: 1, roleAssignments: [ { party: '123456789', role: '1' } ] } }
data = template.fromXML('''<CATSChangeRequest version="r29" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ChangeReasonCode>1</ChangeReasonCode>
<NMIStandingData xsi:type="ase:ElectricityStandingData">
<NMI checksum="1">123456789</NMI>
</NMIStandingData>
</CATSChangeRequest>''')
expect(data).toEqual { changeReasonCode: '1', nmiStandingData: { nmi: '123456789', nmiChecksum: 1 } }
data = template.fromXML('''<CATSChangeRequest version="r29">
<ChangeReasonCode>1</ChangeReasonCode>
<NMIStandingData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ase:ElectricityStandingData" >
<NMI checksum="1">123456789</NMI>
</NMIStandingData>
</CATSChangeRequest>''')
expect(data).toEqual { changeReasonCode: '1', nmiStandingData: { nmi: '123456789', nmiChecksum: 1 } }


it 'should support xinclude to some extent', ->
resolve = (href) -> ['<foo>{{note}}</foo>', resolve]
Expand Down
14 changes: 0 additions & 14 deletions test/model/model-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,6 @@ describe 'the entire model', ->
xml = el.toXML({optIn: 'True'})
expect(xml).toMatchSnapshot()

it 'should get the closest matching element', ->
el = element('foo').content(
element('bar').attrs(attr('a').value('b')).content(text().bind('c'))
element('bar').attrs(attr('d').value('e')).content(text().bind('f'))
)
expect(el.fromXML(el.toXML({ f: "3" }))).toEqual({ f: "3" })

it 'should match as closely as possible', ->
el = element('foo').content(
element('bar').content(text().bind('a'))
element('bar').attrs(attr('d').value('e')).content(text().bind('b'))
)
expect(el.fromXML('<foo><bar d="e">zaz</bar></foo>')).toEqual({'b': 'zaz'})

it 'should allow you bind to array elements', ->
el = element('foo').content(
text().bind('a.b[0]')
Expand Down
Loading