Skip to content
Merged
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
26 changes: 11 additions & 15 deletions tests/cli/base_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ mod passing {
// STDOUT should contain newly added base URL
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<base href=\"http://localhost:8000/\"></base>\
</head><body>Hello, World!</body></html>\n"
r#"<html><head><base href="http://localhost:8000/"></base></head><body>Hello, World!</body></html>
"#
);

// Exit code should be 0
Expand All @@ -42,7 +41,7 @@ mod passing {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let out = cmd
.arg("-M")
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
.output()
.unwrap();

Expand All @@ -52,9 +51,8 @@ mod passing {
// STDOUT should contain newly added base URL
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<base href=\"http://localhost:8000/\">\
</head><body>Hello, World!</body></html>\n"
r#"<html><head><base href="http://localhost:8000/"></head><body>Hello, World!</body></html>
"#
);

// Exit code should be 0
Expand All @@ -68,7 +66,7 @@ mod passing {
.arg("-M")
.arg("-b")
.arg("http://localhost/")
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
.output()
.unwrap();

Expand All @@ -78,9 +76,8 @@ mod passing {
// STDOUT should contain newly added base URL
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<base href=\"http://localhost/\">\
</head><body>Hello, World!</body></html>\n"
r#"<html><head><base href="http://localhost/"></head><body>Hello, World!</body></html>
"#
);

// Exit code should be 0
Expand All @@ -94,7 +91,7 @@ mod passing {
.arg("-M")
.arg("-b")
.arg("")
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
.arg(r#"data:text/html,<base href="http://localhost:8000/" />Hello%2C%20World!"#)
.output()
.unwrap();

Expand All @@ -104,9 +101,8 @@ mod passing {
// STDOUT should contain newly added base URL
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<base href=\"\">\
</head><body>Hello, World!</body></html>\n"
r#"<html><head><base href=""></head><body>Hello, World!</body></html>
"#
);

// Exit code should be 0
Expand Down
18 changes: 16 additions & 2 deletions tests/cli/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ mod passing {
// STDOUT should contain HTML created out of STDIN
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head></head><body>Hello from STDIN\n</body></html>\n"
r#"<html><head></head><body>Hello from STDIN
</body></html>
"#
);

// Exit code should be 0
Expand Down Expand Up @@ -103,7 +105,19 @@ mod passing {
// STDOUT should contain embedded CSS url()'s
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head><style>\n\n @charset \"UTF-8\";\n\n @import \"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\";\n\n @import url(\"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\");\n\n @import url(\"data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K\");\n\n</style>\n</head><body></body></html>\n"
r##"<html><head><style>

@charset "UTF-8";

@import "data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K";

@import url("data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K");

@import url("data:text/css;base64,Ym9keXtiYWNrZ3JvdW5kLWNvbG9yOiMwMDA7Y29sb3I6I2ZmZn0K");

</style>
</head><body></body></html>
"##
);

// Exit code should be 0
Expand Down
45 changes: 14 additions & 31 deletions tests/cli/data_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ mod passing {
// STDOUT should contain isolated HTML
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'unsafe-eval' 'unsafe-inline' data:;\"></meta>\
</head><body>Hello, World!</body></html>\n"
r#"<html><head><meta http-equiv="Content-Security-Policy" content="default-src 'unsafe-eval' 'unsafe-inline' data:;"></meta></head><body>Hello, World!</body></html>
"#
);

// Exit code should be 0
Expand All @@ -54,10 +53,8 @@ mod passing {
// STDOUT should contain HTML with no CSS
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"style-src 'none';\"></meta>\
<style></style>\
</head><body>Hello</body></html>\n"
r#"<html><head><meta http-equiv="Content-Security-Policy" content="style-src 'none';"></meta><style></style></head><body>Hello</body></html>
"#
);

// Exit code should be 0
Expand All @@ -80,10 +77,8 @@ mod passing {
// STDOUT should contain HTML with no web fonts
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"font-src 'none';\"></meta>\
<style></style>\
</head><body>Hi</body></html>\n"
r#"<html><head><meta http-equiv="Content-Security-Policy" content="font-src 'none';"></meta><style></style></head><body>Hi</body></html>
"#
);

// Exit code should be 0
Expand All @@ -96,7 +91,7 @@ mod passing {
let out = cmd
.arg("-M")
.arg("-f")
.arg("data:text/html,<iframe src=\"https://duckduckgo.com\"></iframe>Hi")
.arg(r#"data:text/html,<iframe src="https://duckduckgo.com"></iframe>Hi"#)
.output()
.unwrap();

Expand All @@ -106,9 +101,8 @@ mod passing {
// STDOUT should contain HTML with no iframes
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html><head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"frame-src 'none'; child-src 'none';\"></meta>\
</head><body><iframe src=\"\"></iframe>Hi</body></html>\n"
r#"<html><head><meta http-equiv="Content-Security-Policy" content="frame-src 'none'; child-src 'none';"></meta></head><body><iframe src=""></iframe>Hi</body></html>
"#
);

// Exit code should be 0
Expand All @@ -132,15 +126,8 @@ mod passing {
assert_eq!(
String::from_utf8_lossy(&out.stdout),
format!(
"<html>\
<head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"img-src data:;\"></meta>\
</head>\
<body>\
<img src=\"{empty_image}\">\
Hi\
</body>\
</html>\n",
r#"<html><head><meta http-equiv="Content-Security-Policy" content="img-src data:;"></meta></head><body><img src="{empty_image}">Hi</body></html>
"#,
empty_image = EMPTY_IMAGE_DATA_URL,
)
);
Expand All @@ -165,12 +152,8 @@ mod passing {
// STDOUT should contain HTML with no JS
assert_eq!(
String::from_utf8_lossy(&out.stdout),
"<html>\
<head>\
<meta http-equiv=\"Content-Security-Policy\" content=\"script-src 'none';\"></meta>\
<script></script></head>\
<body>Hi</body>\
</html>\n"
r#"<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'none';"></meta><script></script></head><body>Hi</body></html>
"#
);

// Exit code should be 0
Expand Down Expand Up @@ -211,7 +194,7 @@ mod failing {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let out = cmd
.arg("-M")
.arg("data:text/html,%3Cscript%20src=\"src/tests/data/basic/local-script.js\"%3E%3C/script%3E")
.arg(r#"data:text/html,%3Cscript%20src="src/tests/data/basic/local-script.js"%3E%3C/script%3E"#)
.output()
.unwrap();

Expand Down
Loading