Skip to content

Commit

Permalink
CHANGELOG.md: update
Browse files Browse the repository at this point in the history
  • Loading branch information
niklak committed Jan 10, 2025
1 parent 06a8fa9 commit 862e192
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ All notable changes to the `dom_query` crate will be documented in this file.

- Implemented `NodeRef::is_match` and `NodeRef::is` methods, which allow checking if a node matches
a given matcher (`&Matcher`) or selector (`&str`) without creating a `Selection` object.

- Implemented `Tree::base_uri`, a quick method that returns the base URI of the document based on the `href` attribute of the `<base>` element. `Document::base_uri` and `NodeRef::base_uri` provide the same functionality. Inspired by [Node: baseURI property]( https://developer.mozilla.org/en-US/docs/Web/API/Node/baseURI).

### Changed

Expand Down
13 changes: 13 additions & 0 deletions tests/node-traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,21 @@ fn test_node_base_uri() {
</html>"#;
let doc = Document::from(contents);

// during first call of .base_uri, the result will be cached with OnceCell
let base_uri = doc.base_uri().unwrap();
assert_eq!(base_uri.as_ref(), "https://www.example.com/");

let sel = doc.select_single("#main");
let node = sel.nodes().first().unwrap();
// using cached result. Access at any node of the tree.
let base_uri = node.base_uri().unwrap();
assert_eq!(base_uri.as_ref(), "https://www.example.com/");
}


#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_node_base_uri_none() {
let doc = Document::from(ANCESTORS_CONTENTS);
assert!(doc.base_uri().is_none());
}

0 comments on commit 862e192

Please sign in to comment.