Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Commit

Permalink
Fixed crash during use resolving.
Browse files Browse the repository at this point in the history
The `--resolve-use` option does not resolve used `use` now.

Closes #132
  • Loading branch information
RazrFalcon committed Jan 28, 2018
1 parent 8d58f75 commit 53d8b64
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Crash during `defs` processing.
- Crash during `use` resolving.
- The `--resolve-use` option does not resolve used `use` now.

## [0.9.3] - 2018-01-17
### Added
Expand Down
31 changes: 31 additions & 0 deletions src/task/resolve_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub fn resolve_use(doc: &Document) {
let mut nodes = Vec::new();

for node in doc.descendants().filter(|n| n.is_tag_name(EId::Use)) {
// The 'use' node should not be used by itself.
if node.is_used() {
continue;
}

if let Some(value) = node.attributes().get_value(AId::XlinkHref) {
if let AttributeValue::Link(ref link) = *value {

Expand Down Expand Up @@ -93,6 +98,7 @@ pub fn resolve_use(doc: &Document) {
}

// TODO: maybe just change the tag name
link.detach();
node.insert_after(&link);

node.remove();
Expand Down Expand Up @@ -178,6 +184,21 @@ mod tests {
</svg>
");

test!(resolve_6,
"<svg>
<defs>
<path id='path1' d='M 10 20 L 10 20'/>
<use id='use2' xlink:href='#path1'/>
</defs>
</svg>",
"<svg>
<defs>
<path id='path1' d='M 10 20 L 10 20'/>
</defs>
</svg>
"
);

test_eq!(keep_1,
"<svg>
<rect id='r1'/>
Expand All @@ -194,5 +215,15 @@ mod tests {
</defs>
<use xlink:href='#r1'/>
</svg>
");

test_eq!(keep_3,
"<svg>
<use id='use1' xlink:href='#use2'/>
<defs>
<path id='path1' d='M 10 20 L 10 20'/>
<use id='use2' xlink:href='#path1'/>
</defs>
</svg>
");
}

0 comments on commit 53d8b64

Please sign in to comment.