@@ -44,7 +44,13 @@ fn main() -> Result<(), Error> {
4444 }
4545
4646 let template = CopyrightTemplate {
47- in_tree : collected_tree_metadata. files ,
47+ // in_tree: collected_tree_metadata.files,
48+ in_tree : Node :: Root {
49+ children : vec ! [ Node :: File {
50+ name: "<script>alert(1)</script>" . to_string( ) ,
51+ license: License { spdx: "" . to_string( ) , copyright: vec![ ] } ,
52+ } ] ,
53+ } ,
4854 dependencies : collected_cargo_metadata,
4955 } ;
5056
@@ -62,6 +68,8 @@ struct Metadata {
6268}
6369
6470/// Describes one node in our metadata tree
71+ #[ derive( Template ) ]
72+ #[ template( path = "node.html" ) ]
6573#[ derive( serde:: Deserialize ) ]
6674#[ serde( rename_all = "kebab-case" , tag = "type" ) ]
6775pub ( crate ) enum Node {
@@ -81,43 +89,43 @@ where
8189 Ok ( ( ) )
8290}
8391
84- impl std:: fmt:: Display for Node {
85- fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
86- match self {
87- Node :: Root { children } => {
88- if children. len ( ) > 1 {
89- with_box ( fmt, |f| {
90- for child in children {
91- writeln ! ( f, "{child}" ) ?;
92- }
93- Ok ( ( ) )
94- } )
95- } else {
96- for child in children {
97- writeln ! ( fmt, "{child}" ) ?;
98- }
99- Ok ( ( ) )
100- }
101- }
102- Node :: Directory { name, children, license } => with_box ( fmt, |f| {
103- render_tree_license ( std:: iter:: once ( name) , license. as_ref ( ) , f) ?;
104- if !children. is_empty ( ) {
105- writeln ! ( f, "<p><b>Exceptions:</b></p>" ) ?;
106- for child in children {
107- writeln ! ( f, "{child}" ) ?;
108- }
109- }
110- Ok ( ( ) )
111- } ) ,
112- Node :: Group { files, directories, license } => with_box ( fmt, |f| {
113- render_tree_license ( directories. iter ( ) . chain ( files. iter ( ) ) , Some ( license) , f)
114- } ) ,
115- Node :: File { name, license } => {
116- with_box ( fmt, |f| render_tree_license ( std:: iter:: once ( name) , Some ( license) , f) )
117- }
118- }
119- }
120- }
92+ // impl std::fmt::Display for Node {
93+ // fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
94+ // match self {
95+ // Node::Root { children } => {
96+ // if children.len() > 1 {
97+ // with_box(fmt, |f| {
98+ // for child in children {
99+ // writeln!(f, "{child}")?;
100+ // }
101+ // Ok(())
102+ // })
103+ // } else {
104+ // for child in children {
105+ // writeln!(fmt, "{child}")?;
106+ // }
107+ // Ok(())
108+ // }
109+ // }
110+ // Node::Directory { name, children, license } => with_box(fmt, |f| {
111+ // render_tree_license(std::iter::once(name), license.as_ref(), f)?;
112+ // if !children.is_empty() {
113+ // writeln!(f, "<p><b>Exceptions:</b></p>")?;
114+ // for child in children {
115+ // writeln!(f, "{child}")?;
116+ // }
117+ // }
118+ // Ok(())
119+ // }),
120+ // Node::Group { files, directories, license } => with_box(fmt, |f| {
121+ // render_tree_license(directories.iter().chain(files.iter()), Some(license), f)
122+ // }),
123+ // Node::File { name, license } => {
124+ // with_box(fmt, |f| render_tree_license(std::iter::once(name), Some(license), f))
125+ // }
126+ // }
127+ // }
128+ // }
121129
122130/// Draw a series of sibling files/folders, as HTML, into the given formatter.
123131fn render_tree_license < ' a > (
0 commit comments