Merge pull request #284 from snshn/move-tests-to-upper-level
Get rid of macros, move tests out of src
This commit is contained in:
commit
a11c4496b0
71 changed files with 272 additions and 262 deletions
36
src/css.rs
36
src/css.rs
|
@ -6,7 +6,7 @@ use std::collections::HashMap;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::opts::Options;
|
use crate::opts::Options;
|
||||||
use crate::url::{create_data_url, resolve_url};
|
use crate::url::{create_data_url, resolve_url, EMPTY_IMAGE_DATA_URL};
|
||||||
use crate::utils::retrieve_asset;
|
use crate::utils::retrieve_asset;
|
||||||
|
|
||||||
const CSS_PROPS_WITH_IMAGE_URLS: &[&str] = &[
|
const CSS_PROPS_WITH_IMAGE_URLS: &[&str] = &[
|
||||||
|
@ -56,14 +56,14 @@ pub fn embed_css(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_ident(ident: &str) -> String {
|
pub fn format_ident(ident: &str) -> String {
|
||||||
let mut res: String = String::new();
|
let mut res: String = "".to_string();
|
||||||
let _ = serialize_identifier(ident, &mut res);
|
let _ = serialize_identifier(ident, &mut res);
|
||||||
res = res.trim_end().to_string();
|
res = res.trim_end().to_string();
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_quoted_string(string: &str) -> String {
|
pub fn format_quoted_string(string: &str) -> String {
|
||||||
let mut res: String = String::new();
|
let mut res: String = "".to_string();
|
||||||
let _ = serialize_string(string, &mut res);
|
let _ = serialize_string(string, &mut res);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -86,10 +86,10 @@ pub fn process_css<'a>(
|
||||||
prop_name: &str,
|
prop_name: &str,
|
||||||
func_name: &str,
|
func_name: &str,
|
||||||
) -> Result<String, ParseError<'a, String>> {
|
) -> Result<String, ParseError<'a, String>> {
|
||||||
let mut result: String = str!();
|
let mut result: String = "".to_string();
|
||||||
|
|
||||||
let mut curr_rule: String = str!(rule_name.clone());
|
let mut curr_rule: String = rule_name.clone().to_string();
|
||||||
let mut curr_prop: String = str!(prop_name.clone());
|
let mut curr_prop: String = prop_name.clone().to_string();
|
||||||
let mut token: &Token;
|
let mut token: &Token;
|
||||||
let mut token_offset: SourcePosition;
|
let mut token_offset: SourcePosition;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ pub fn process_css<'a>(
|
||||||
match *token {
|
match *token {
|
||||||
Token::Comment(_) => {
|
Token::Comment(_) => {
|
||||||
let token_slice = parser.slice_from(token_offset);
|
let token_slice = parser.slice_from(token_offset);
|
||||||
result.push_str(str!(token_slice).as_str());
|
result.push_str(token_slice);
|
||||||
}
|
}
|
||||||
Token::Semicolon => result.push_str(";"),
|
Token::Semicolon => result.push_str(";"),
|
||||||
Token::Colon => result.push_str(":"),
|
Token::Colon => result.push_str(":"),
|
||||||
|
@ -161,13 +161,13 @@ pub fn process_css<'a>(
|
||||||
}
|
}
|
||||||
// div...
|
// div...
|
||||||
Token::Ident(ref value) => {
|
Token::Ident(ref value) => {
|
||||||
curr_rule = str!();
|
curr_rule = "".to_string();
|
||||||
curr_prop = str!(value);
|
curr_prop = value.to_string();
|
||||||
result.push_str(&format_ident(value));
|
result.push_str(&format_ident(value));
|
||||||
}
|
}
|
||||||
// @import, @font-face, @charset, @media...
|
// @import, @font-face, @charset, @media...
|
||||||
Token::AtKeyword(ref value) => {
|
Token::AtKeyword(ref value) => {
|
||||||
curr_rule = str!(value);
|
curr_rule = value.to_string();
|
||||||
if options.no_fonts && curr_rule == "font-face" {
|
if options.no_fonts && curr_rule == "font-face" {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ pub fn process_css<'a>(
|
||||||
Token::QuotedString(ref value) => {
|
Token::QuotedString(ref value) => {
|
||||||
if curr_rule == "import" {
|
if curr_rule == "import" {
|
||||||
// Reset current at-rule value
|
// Reset current at-rule value
|
||||||
curr_rule = str!();
|
curr_rule = "".to_string();
|
||||||
|
|
||||||
// Skip empty import values
|
// Skip empty import values
|
||||||
if value.len() == 0 {
|
if value.len() == 0 {
|
||||||
|
@ -242,7 +242,7 @@ pub fn process_css<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.no_images && is_image_url_prop(curr_prop.as_str()) {
|
if options.no_images && is_image_url_prop(curr_prop.as_str()) {
|
||||||
result.push_str(format_quoted_string(empty_image!()).as_str());
|
result.push_str(format_quoted_string(EMPTY_IMAGE_DATA_URL).as_str());
|
||||||
} else {
|
} else {
|
||||||
let resolved_url: Url = resolve_url(&document_url, value);
|
let resolved_url: Url = resolve_url(&document_url, value);
|
||||||
match retrieve_asset(
|
match retrieve_asset(
|
||||||
|
@ -297,7 +297,7 @@ pub fn process_css<'a>(
|
||||||
if *has_sign && *unit_value >= 0. {
|
if *has_sign && *unit_value >= 0. {
|
||||||
result.push_str("+");
|
result.push_str("+");
|
||||||
}
|
}
|
||||||
result.push_str(str!(unit_value * 100.0).as_str());
|
result.push_str(&(unit_value * 100.0).to_string());
|
||||||
result.push_str("%");
|
result.push_str("%");
|
||||||
}
|
}
|
||||||
Token::Dimension {
|
Token::Dimension {
|
||||||
|
@ -309,12 +309,12 @@ pub fn process_css<'a>(
|
||||||
if *has_sign && *value >= 0. {
|
if *has_sign && *value >= 0. {
|
||||||
result.push_str("+");
|
result.push_str("+");
|
||||||
}
|
}
|
||||||
result.push_str(str!(value).as_str());
|
result.push_str(&value.to_string());
|
||||||
result.push_str(str!(unit).as_str());
|
result.push_str(&unit.to_string());
|
||||||
}
|
}
|
||||||
// #selector, #id...
|
// #selector, #id...
|
||||||
Token::IDHash(ref value) => {
|
Token::IDHash(ref value) => {
|
||||||
curr_rule = str!();
|
curr_rule = "".to_string();
|
||||||
result.push_str("#");
|
result.push_str("#");
|
||||||
result.push_str(&format_ident(value));
|
result.push_str(&format_ident(value));
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ pub fn process_css<'a>(
|
||||||
|
|
||||||
if is_import {
|
if is_import {
|
||||||
// Reset current at-rule value
|
// Reset current at-rule value
|
||||||
curr_rule = str!();
|
curr_rule = "".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip empty url()'s
|
// Skip empty url()'s
|
||||||
|
@ -377,7 +377,7 @@ pub fn process_css<'a>(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if is_image_url_prop(curr_prop.as_str()) && options.no_images {
|
if is_image_url_prop(curr_prop.as_str()) && options.no_images {
|
||||||
result.push_str(format_quoted_string(empty_image!()).as_str());
|
result.push_str(format_quoted_string(EMPTY_IMAGE_DATA_URL).as_str());
|
||||||
} else {
|
} else {
|
||||||
let full_url: Url = resolve_url(&document_url, value);
|
let full_url: Url = resolve_url(&document_url, value);
|
||||||
match retrieve_asset(
|
match retrieve_asset(
|
||||||
|
|
48
src/html.rs
48
src/html.rs
|
@ -18,7 +18,9 @@ use std::default::Default;
|
||||||
use crate::css::embed_css;
|
use crate::css::embed_css;
|
||||||
use crate::js::attr_is_event_handler;
|
use crate::js::attr_is_event_handler;
|
||||||
use crate::opts::Options;
|
use crate::opts::Options;
|
||||||
use crate::url::{clean_url, create_data_url, is_url_and_has_protocol, resolve_url};
|
use crate::url::{
|
||||||
|
clean_url, create_data_url, is_url_and_has_protocol, resolve_url, EMPTY_IMAGE_DATA_URL,
|
||||||
|
};
|
||||||
use crate::utils::{parse_content_type, retrieve_asset};
|
use crate::utils::{parse_content_type, retrieve_asset};
|
||||||
|
|
||||||
struct SrcSetItem<'a> {
|
struct SrcSetItem<'a> {
|
||||||
|
@ -173,11 +175,11 @@ pub fn embed_srcset(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut result: String = str!();
|
let mut result: String = "".to_string();
|
||||||
let mut i: usize = array.len();
|
let mut i: usize = array.len();
|
||||||
for part in array {
|
for part in array {
|
||||||
if options.no_images {
|
if options.no_images {
|
||||||
result.push_str(empty_image!());
|
result.push_str(EMPTY_IMAGE_DATA_URL);
|
||||||
} else {
|
} else {
|
||||||
let image_full_url: Url = resolve_url(&document_url, part.path);
|
let image_full_url: Url = resolve_url(&document_url, part.path);
|
||||||
match retrieve_asset(
|
match retrieve_asset(
|
||||||
|
@ -205,7 +207,7 @@ pub fn embed_srcset(
|
||||||
result.push_str(image_full_url.as_ref());
|
result.push_str(image_full_url.as_ref());
|
||||||
} else {
|
} else {
|
||||||
// Avoid breaking the structure in case if not an HTTP(S) URL
|
// Avoid breaking the structure in case if not an HTTP(S) URL
|
||||||
result.push_str(empty_image!());
|
result.push_str(EMPTY_IMAGE_DATA_URL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +344,7 @@ pub fn get_node_attr(node: &Handle, attr_name: &str) -> Option<String> {
|
||||||
NodeData::Element { ref attrs, .. } => {
|
NodeData::Element { ref attrs, .. } => {
|
||||||
for attr in attrs.borrow().iter() {
|
for attr in attrs.borrow().iter() {
|
||||||
if &*attr.name.local == attr_name {
|
if &*attr.name.local == attr_name {
|
||||||
return Some(str!(&*attr.value));
|
return Some(attr.value.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -827,10 +829,10 @@ pub fn walk_and_embed_assets(
|
||||||
if options.no_images {
|
if options.no_images {
|
||||||
// Put empty images into src and data-src attributes
|
// Put empty images into src and data-src attributes
|
||||||
if img_attr_src_value != None {
|
if img_attr_src_value != None {
|
||||||
set_node_attr(node, "src", Some(str!(empty_image!())));
|
set_node_attr(node, "src", Some(EMPTY_IMAGE_DATA_URL.to_string()));
|
||||||
}
|
}
|
||||||
if img_attr_data_src_value != None {
|
if img_attr_data_src_value != None {
|
||||||
set_node_attr(node, "data-src", Some(str!(empty_image!())));
|
set_node_attr(node, "data-src", Some(EMPTY_IMAGE_DATA_URL.to_string()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if img_attr_src_value.clone().unwrap_or_default().is_empty()
|
if img_attr_src_value.clone().unwrap_or_default().is_empty()
|
||||||
|
@ -840,7 +842,7 @@ pub fn walk_and_embed_assets(
|
||||||
.is_empty()
|
.is_empty()
|
||||||
{
|
{
|
||||||
// Add empty src attribute
|
// Add empty src attribute
|
||||||
set_node_attr(node, "src", Some(str!()));
|
set_node_attr(node, "src", Some("".to_string()));
|
||||||
} else {
|
} else {
|
||||||
// Add data URL src attribute
|
// Add data URL src attribute
|
||||||
let img_full_url: String = if !img_attr_data_src_value
|
let img_full_url: String = if !img_attr_data_src_value
|
||||||
|
@ -891,11 +893,11 @@ pub fn walk_and_embed_assets(
|
||||||
if let Some(input_attr_src_value) = get_node_attr(node, "src") {
|
if let Some(input_attr_src_value) = get_node_attr(node, "src") {
|
||||||
if options.no_images || input_attr_src_value.is_empty() {
|
if options.no_images || input_attr_src_value.is_empty() {
|
||||||
let value = if input_attr_src_value.is_empty() {
|
let value = if input_attr_src_value.is_empty() {
|
||||||
str!()
|
""
|
||||||
} else {
|
} else {
|
||||||
str!(empty_image!())
|
EMPTY_IMAGE_DATA_URL
|
||||||
};
|
};
|
||||||
set_node_attr(node, "src", Some(value));
|
set_node_attr(node, "src", Some(value.to_string()));
|
||||||
} else {
|
} else {
|
||||||
retrieve_and_embed_asset(
|
retrieve_and_embed_asset(
|
||||||
cache,
|
cache,
|
||||||
|
@ -913,7 +915,7 @@ pub fn walk_and_embed_assets(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"image" => {
|
"image" => {
|
||||||
let mut image_href: String = str!();
|
let mut image_href: String = "".to_string();
|
||||||
|
|
||||||
if let Some(image_attr_href_value) = get_node_attr(node, "href") {
|
if let Some(image_attr_href_value) = get_node_attr(node, "href") {
|
||||||
image_href = image_attr_href_value;
|
image_href = image_attr_href_value;
|
||||||
|
@ -984,7 +986,11 @@ pub fn walk_and_embed_assets(
|
||||||
if parent_node_name == "picture" {
|
if parent_node_name == "picture" {
|
||||||
if !source_attr_srcset_value.is_empty() {
|
if !source_attr_srcset_value.is_empty() {
|
||||||
if options.no_images {
|
if options.no_images {
|
||||||
set_node_attr(node, "srcset", Some(str!(empty_image!())));
|
set_node_attr(
|
||||||
|
node,
|
||||||
|
"srcset",
|
||||||
|
Some(EMPTY_IMAGE_DATA_URL.to_string()),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
let resolved_srcset: String = embed_srcset(
|
let resolved_srcset: String = embed_srcset(
|
||||||
cache,
|
cache,
|
||||||
|
@ -1009,7 +1015,7 @@ pub fn walk_and_embed_assets(
|
||||||
{
|
{
|
||||||
if options.no_js {
|
if options.no_js {
|
||||||
// Replace with empty JS call to preserve original behavior
|
// Replace with empty JS call to preserve original behavior
|
||||||
set_node_attr(node, "href", Some(str!("javascript:;")));
|
set_node_attr(node, "href", Some("javascript:;".to_string()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Don't touch mailto: links or hrefs which begin with a hash sign
|
// Don't touch mailto: links or hrefs which begin with a hash sign
|
||||||
|
@ -1083,7 +1089,7 @@ pub fn walk_and_embed_assets(
|
||||||
if let Some(frame_attr_src_value) = get_node_attr(node, "src") {
|
if let Some(frame_attr_src_value) = get_node_attr(node, "src") {
|
||||||
if options.no_frames {
|
if options.no_frames {
|
||||||
// Empty the src attribute
|
// Empty the src attribute
|
||||||
set_node_attr(node, "src", Some(str!()));
|
set_node_attr(node, "src", Some("".to_string()));
|
||||||
} else {
|
} else {
|
||||||
// Ignore (i)frames with empty source (they cause infinite loops)
|
// Ignore (i)frames with empty source (they cause infinite loops)
|
||||||
if !frame_attr_src_value.trim().is_empty() {
|
if !frame_attr_src_value.trim().is_empty() {
|
||||||
|
@ -1144,7 +1150,11 @@ pub fn walk_and_embed_assets(
|
||||||
// Skip posters with empty source
|
// Skip posters with empty source
|
||||||
if !video_attr_poster_value.is_empty() {
|
if !video_attr_poster_value.is_empty() {
|
||||||
if options.no_images {
|
if options.no_images {
|
||||||
set_node_attr(node, "poster", Some(str!(empty_image!())));
|
set_node_attr(
|
||||||
|
node,
|
||||||
|
"poster",
|
||||||
|
Some(EMPTY_IMAGE_DATA_URL.to_string()),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
retrieve_and_embed_asset(
|
retrieve_and_embed_asset(
|
||||||
cache,
|
cache,
|
||||||
|
@ -1167,8 +1177,10 @@ pub fn walk_and_embed_assets(
|
||||||
// Get contents of NOSCRIPT node
|
// Get contents of NOSCRIPT node
|
||||||
let mut noscript_contents = contents.borrow_mut();
|
let mut noscript_contents = contents.borrow_mut();
|
||||||
// Parse contents of NOSCRIPT node as DOM
|
// Parse contents of NOSCRIPT node as DOM
|
||||||
let noscript_contents_dom: RcDom =
|
let noscript_contents_dom: RcDom = html_to_dom(
|
||||||
html_to_dom(&noscript_contents.as_bytes().to_vec(), str!());
|
&noscript_contents.as_bytes().to_vec(),
|
||||||
|
"".to_string(),
|
||||||
|
);
|
||||||
// Embed assets of NOSCRIPT node contents
|
// Embed assets of NOSCRIPT node contents
|
||||||
walk_and_embed_assets(
|
walk_and_embed_assets(
|
||||||
cache,
|
cache,
|
||||||
|
|
|
@ -1,15 +1,6 @@
|
||||||
#[macro_use]
|
|
||||||
extern crate clap;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
mod macros;
|
|
||||||
|
|
||||||
pub mod css;
|
pub mod css;
|
||||||
pub mod html;
|
pub mod html;
|
||||||
pub mod js;
|
pub mod js;
|
||||||
pub mod opts;
|
pub mod opts;
|
||||||
pub mod url;
|
pub mod url;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub mod tests;
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
#[macro_export]
|
|
||||||
macro_rules! str {
|
|
||||||
() => {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
($val: expr) => {
|
|
||||||
ToString::to_string(&$val)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! empty_image {
|
|
||||||
() => {
|
|
||||||
"data:image/png;base64,\
|
|
||||||
iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAQAAADY4iz3AAAAEUlEQVR42mNkwAkYR6UolgIACvgADsuK6xYAAAAASUVORK5CYII="
|
|
||||||
};
|
|
||||||
}
|
|
15
src/main.rs
15
src/main.rs
|
@ -18,8 +18,6 @@ use monolith::opts::Options;
|
||||||
use monolith::url::{create_data_url, resolve_url};
|
use monolith::url::{create_data_url, resolve_url};
|
||||||
use monolith::utils::retrieve_asset;
|
use monolith::utils::retrieve_asset;
|
||||||
|
|
||||||
mod macros;
|
|
||||||
|
|
||||||
enum Output {
|
enum Output {
|
||||||
Stdout(io::Stdout),
|
Stdout(io::Stdout),
|
||||||
File(fs::File),
|
File(fs::File),
|
||||||
|
@ -67,7 +65,7 @@ pub fn read_stdin() -> Vec<u8> {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let options = Options::from_args();
|
let options = Options::from_args();
|
||||||
let mut target: String = str!(&options.target.clone());
|
let mut target: String = options.target.clone();
|
||||||
|
|
||||||
// Check if target was provided
|
// Check if target was provided
|
||||||
if target.len() == 0 {
|
if target.len() == 0 {
|
||||||
|
@ -170,7 +168,7 @@ fn main() {
|
||||||
let mut base_url: Url = target_url.clone();
|
let mut base_url: Url = target_url.clone();
|
||||||
|
|
||||||
let data: Vec<u8>;
|
let data: Vec<u8>;
|
||||||
let mut document_encoding: String = str!();
|
let mut document_encoding: String = "".to_string();
|
||||||
let mut dom: RcDom;
|
let mut dom: RcDom;
|
||||||
|
|
||||||
// Retrieve target document
|
// Retrieve target document
|
||||||
|
@ -190,7 +188,12 @@ fn main() {
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if options.base_url.clone().unwrap_or(str!()).is_empty() {
|
if options
|
||||||
|
.base_url
|
||||||
|
.clone()
|
||||||
|
.unwrap_or("".to_string())
|
||||||
|
.is_empty()
|
||||||
|
{
|
||||||
base_url = final_url;
|
base_url = final_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +229,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use custom base URL if specified, read and use what's in the DOM otherwise
|
// Use custom base URL if specified, read and use what's in the DOM otherwise
|
||||||
let custom_base_url: String = options.base_url.clone().unwrap_or(str!());
|
let custom_base_url: String = options.base_url.clone().unwrap_or("".to_string());
|
||||||
if custom_base_url.is_empty() {
|
if custom_base_url.is_empty() {
|
||||||
// No custom base URL is specified
|
// No custom base URL is specified
|
||||||
// Try to see if document has BASE element
|
// Try to see if document has BASE element
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use clap::{App, Arg};
|
use clap::{crate_authors, crate_description, crate_version, App, Arg};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -85,11 +85,11 @@ impl Options {
|
||||||
.to_string();
|
.to_string();
|
||||||
options.no_audio = app.is_present("no-audio");
|
options.no_audio = app.is_present("no-audio");
|
||||||
if let Some(base_url) = app.value_of("base-url") {
|
if let Some(base_url) = app.value_of("base-url") {
|
||||||
options.base_url = Some(str!(base_url));
|
options.base_url = Some(base_url.to_string());
|
||||||
}
|
}
|
||||||
options.no_css = app.is_present("no-css");
|
options.no_css = app.is_present("no-css");
|
||||||
if let Some(charset) = app.value_of("charset") {
|
if let Some(charset) = app.value_of("charset") {
|
||||||
options.charset = Some(str!(charset));
|
options.charset = Some(charset.to_string());
|
||||||
}
|
}
|
||||||
options.ignore_errors = app.is_present("ignore-errors");
|
options.ignore_errors = app.is_present("ignore-errors");
|
||||||
options.no_frames = app.is_present("no-frames");
|
options.no_frames = app.is_present("no-frames");
|
||||||
|
@ -107,7 +107,7 @@ impl Options {
|
||||||
.parse::<u64>()
|
.parse::<u64>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if let Some(user_agent) = app.value_of("user-agent") {
|
if let Some(user_agent) = app.value_of("user-agent") {
|
||||||
options.user_agent = Some(str!(user_agent));
|
options.user_agent = Some(user_agent.to_string());
|
||||||
} else {
|
} else {
|
||||||
options.user_agent = Some(DEFAULT_USER_AGENT.to_string());
|
options.user_agent = Some(DEFAULT_USER_AGENT.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,9 @@ use url::{form_urlencoded, Url};
|
||||||
|
|
||||||
use crate::utils::{detect_media_type, parse_content_type};
|
use crate::utils::{detect_media_type, parse_content_type};
|
||||||
|
|
||||||
|
pub const EMPTY_IMAGE_DATA_URL: &'static str = "data:image/png;base64,\
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAQAAADY4iz3AAAAEUlEQVR42mNkwAkYR6UolgIACvgADsuK6xYAAAAASUVORK5CYII=";
|
||||||
|
|
||||||
pub fn clean_url(url: Url) -> Url {
|
pub fn clean_url(url: Url) -> Url {
|
||||||
let mut url = url.clone();
|
let mut url = url.clone();
|
||||||
|
|
||||||
|
@ -26,7 +29,7 @@ pub fn create_data_url(media_type: &str, charset: &str, data: &[u8], final_asset
|
||||||
if !charset.trim().is_empty() && !charset.trim().eq_ignore_ascii_case("US-ASCII") {
|
if !charset.trim().is_empty() && !charset.trim().eq_ignore_ascii_case("US-ASCII") {
|
||||||
format!(";charset={}", charset.trim())
|
format!(";charset={}", charset.trim())
|
||||||
} else {
|
} else {
|
||||||
str!()
|
"".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
data_url.set_path(format!("{}{};base64,{}", media_type, c, base64::encode(data)).as_str());
|
data_url.set_path(format!("{}{};base64,{}", media_type, c, base64::encode(data)).as_str());
|
||||||
|
@ -75,9 +78,9 @@ pub fn percent_decode(input: String) -> String {
|
||||||
[
|
[
|
||||||
key.to_string(),
|
key.to_string(),
|
||||||
if val.to_string().len() == 0 {
|
if val.to_string().len() == 0 {
|
||||||
str!()
|
"".to_string()
|
||||||
} else {
|
} else {
|
||||||
str!('=')
|
"=".to_string()
|
||||||
},
|
},
|
||||||
val.to_string(),
|
val.to_string(),
|
||||||
]
|
]
|
||||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -110,8 +110,8 @@ pub fn is_plaintext_media_type(media_type: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_content_type(content_type: &str) -> (String, String, bool) {
|
pub fn parse_content_type(content_type: &str) -> (String, String, bool) {
|
||||||
let mut media_type: String = str!("text/plain");
|
let mut media_type: String = "text/plain".to_string();
|
||||||
let mut charset: String = str!("US-ASCII");
|
let mut charset: String = "US-ASCII".to_string();
|
||||||
let mut is_base64: bool = false;
|
let mut is_base64: bool = false;
|
||||||
|
|
||||||
// Parse meta data
|
// Parse meta data
|
||||||
|
@ -120,7 +120,7 @@ pub fn parse_content_type(content_type: &str) -> (String, String, bool) {
|
||||||
for item in &content_type_items {
|
for item in &content_type_items {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if item.trim().len() > 0 {
|
if item.trim().len() > 0 {
|
||||||
media_type = str!(item.trim());
|
media_type = item.trim().to_string();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if item.trim().eq_ignore_ascii_case("base64") {
|
if item.trim().eq_ignore_ascii_case("base64") {
|
||||||
|
@ -199,7 +199,7 @@ pub fn retrieve_asset(
|
||||||
file_blob.clone(),
|
file_blob.clone(),
|
||||||
url.clone(),
|
url.clone(),
|
||||||
detect_media_type(&file_blob, url),
|
detect_media_type(&file_blob, url),
|
||||||
str!(),
|
"".to_string(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -232,8 +232,8 @@ pub fn retrieve_asset(
|
||||||
Ok((
|
Ok((
|
||||||
cache.get(&cache_key).unwrap().to_vec(),
|
cache.get(&cache_key).unwrap().to_vec(),
|
||||||
url.clone(),
|
url.clone(),
|
||||||
str!(),
|
"".to_string(),
|
||||||
str!(),
|
"".to_string(),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
// URL not in cache, we retrieve the file
|
// URL not in cache, we retrieve the file
|
||||||
|
|
|
@ -77,8 +77,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn css_import_string() {
|
fn css_import_string() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/css/index.html");
|
let path_html: &Path = Path::new("tests/data/css/index.html");
|
||||||
let path_css: &Path = Path::new("src/tests/data/css/style.css");
|
let path_css: &Path = Path::new("tests/data/css/style.css");
|
||||||
|
|
||||||
assert!(path_html.is_file());
|
assert!(path_html.is_file());
|
||||||
assert!(path_css.is_file());
|
assert!(path_css.is_file());
|
|
@ -11,6 +11,8 @@ mod passing {
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn isolate_data_url() {
|
fn isolate_data_url() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
|
@ -139,7 +141,7 @@ mod passing {
|
||||||
Hi\
|
Hi\
|
||||||
</body>\
|
</body>\
|
||||||
</html>\n",
|
</html>\n",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,15 +14,20 @@ mod passing {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn local_file_target_input_relative_target_path() {
|
fn local_file_target_input_relative_target_path() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let cwd_normalized: String =
|
let cwd_normalized: String = env::current_dir()
|
||||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace("\\", "/");
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}basic{s}local-file.html",
|
"tests{s}data{s}basic{s}local-file.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.output()
|
.output()
|
||||||
|
@ -34,11 +39,11 @@ mod passing {
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"\
|
"\
|
||||||
{file}{cwd}/src/tests/data/basic/local-file.html\n \
|
{file}{cwd}/tests/data/basic/local-file.html\n \
|
||||||
{file}{cwd}/src/tests/data/basic/local-style.css\n \
|
{file}{cwd}/tests/data/basic/local-style.css\n \
|
||||||
{file}{cwd}/src/tests/data/basic/local-style-does-not-exist.css (not found)\n \
|
{file}{cwd}/tests/data/basic/local-style-does-not-exist.css (not found)\n \
|
||||||
{file}{cwd}/src/tests/data/basic/monolith.png (not found)\n \
|
{file}{cwd}/tests/data/basic/monolith.png (not found)\n \
|
||||||
{file}{cwd}/src/tests/data/basic/local-script.js\n\
|
{file}{cwd}/tests/data/basic/local-script.js\n\
|
||||||
",
|
",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized
|
cwd = cwd_normalized
|
||||||
|
@ -69,7 +74,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn local_file_target_input_absolute_target_path() {
|
fn local_file_target_input_absolute_target_path() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/basic/local-file.html");
|
let path_html: &Path = Path::new("tests/data/basic/local-file.html");
|
||||||
|
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
|
@ -104,7 +109,7 @@ mod passing {
|
||||||
<script></script>\n\n\n\n\
|
<script></script>\n\n\n\n\
|
||||||
</body></html>\n\
|
</body></html>\n\
|
||||||
",
|
",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -115,14 +120,17 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn local_file_url_target_input() {
|
fn local_file_url_target_input() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let cwd_normalized: String =
|
let cwd_normalized: String = env::current_dir()
|
||||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace("\\", "/");
|
||||||
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg("-cji")
|
.arg("-cji")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"{file}{cwd}/src/tests/data/basic/local-file.html",
|
"{file}{cwd}/tests/data/basic/local-file.html",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
))
|
))
|
||||||
|
@ -133,7 +141,7 @@ mod passing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/basic/local-file.html\n",
|
"{file}{cwd}/tests/data/basic/local-file.html\n",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
||||||
|
@ -156,7 +164,7 @@ mod passing {
|
||||||
<script></script>\n\n\n\n\
|
<script></script>\n\n\n\n\
|
||||||
</body></html>\n\
|
</body></html>\n\
|
||||||
",
|
",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -167,8 +175,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn embed_file_url_local_asset_within_style_attribute() {
|
fn embed_file_url_local_asset_within_style_attribute() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/svg/index.html");
|
let path_html: &Path = Path::new("tests/data/svg/index.html");
|
||||||
let path_svg: &Path = Path::new("src/tests/data/svg/image.svg");
|
let path_svg: &Path = Path::new("tests/data/svg/image.svg");
|
||||||
|
|
||||||
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
||||||
|
|
||||||
|
@ -198,21 +206,24 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn discard_integrity_for_local_files() {
|
fn discard_integrity_for_local_files() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let cwd_normalized: String =
|
let cwd_normalized: String = env::current_dir()
|
||||||
str!(env::current_dir().unwrap().to_str().unwrap()).replace("\\", "/");
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.replace("\\", "/");
|
||||||
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
let file_url_protocol: &str = if cfg!(windows) { "file:///" } else { "file://" };
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(if cfg!(windows) {
|
.arg(if cfg!(windows) {
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/integrity/index.html",
|
"{file}{cwd}/tests/data/integrity/index.html",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/integrity/index.html",
|
"{file}{cwd}/tests/data/integrity/index.html",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
||||||
|
@ -225,11 +236,11 @@ mod passing {
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"\
|
"\
|
||||||
{file}{cwd}/src/tests/data/integrity/index.html\n \
|
{file}{cwd}/tests/data/integrity/index.html\n \
|
||||||
{file}{cwd}/src/tests/data/integrity/style.css\n \
|
{file}{cwd}/tests/data/integrity/style.css\n \
|
||||||
{file}{cwd}/src/tests/data/integrity/style.css\n \
|
{file}{cwd}/tests/data/integrity/style.css\n \
|
||||||
{file}{cwd}/src/tests/data/integrity/script.js\n \
|
{file}{cwd}/tests/data/integrity/script.js\n \
|
||||||
{file}{cwd}/src/tests/data/integrity/script.js\n\
|
{file}{cwd}/tests/data/integrity/script.js\n\
|
||||||
",
|
",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
|
@ -17,8 +17,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_noscript_contents() {
|
fn parse_noscript_contents() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/noscript/index.html");
|
let path_html: &Path = Path::new("tests/data/noscript/index.html");
|
||||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||||
|
|
||||||
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
let out = cmd.arg("-M").arg(path_html.as_os_str()).output().unwrap();
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn unwrap_noscript_contents() {
|
fn unwrap_noscript_contents() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/noscript/index.html");
|
let path_html: &Path = Path::new("tests/data/noscript/index.html");
|
||||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||||
|
|
||||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn unwrap_noscript_contents_nested() {
|
fn unwrap_noscript_contents_nested() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/noscript/nested.html");
|
let path_html: &Path = Path::new("tests/data/noscript/nested.html");
|
||||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||||
|
|
||||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||||
|
|
||||||
|
@ -110,8 +110,8 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn unwrap_noscript_contents_with_script() {
|
fn unwrap_noscript_contents_with_script() {
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let path_html: &Path = Path::new("src/tests/data/noscript/script.html");
|
let path_html: &Path = Path::new("tests/data/noscript/script.html");
|
||||||
let path_svg: &Path = Path::new("src/tests/data/noscript/image.svg");
|
let path_svg: &Path = Path::new("tests/data/noscript/image.svg");
|
||||||
|
|
||||||
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
let out = cmd.arg("-Mn").arg(path_html.as_os_str()).output().unwrap();
|
||||||
|
|
|
@ -16,12 +16,12 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn properly_save_document_with_gb2312() {
|
fn properly_save_document_with_gb2312() {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.output()
|
.output()
|
||||||
|
@ -32,7 +32,7 @@ mod passing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/unusual_encodings/gb2312.html\n",
|
"{file}{cwd}/tests/data/unusual_encodings/gb2312.html\n",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
||||||
|
@ -67,7 +67,7 @@ mod passing {
|
||||||
fn properly_save_document_with_gb2312_from_stdin() {
|
fn properly_save_document_with_gb2312_from_stdin() {
|
||||||
let mut echo = Command::new("cat")
|
let mut echo = Command::new("cat")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
|
@ -111,14 +111,14 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn properly_save_document_with_gb2312_custom_charset() {
|
fn properly_save_document_with_gb2312_custom_charset() {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg("utf8")
|
.arg("utf8")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.output()
|
.output()
|
||||||
|
@ -129,7 +129,7 @@ mod passing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/unusual_encodings/gb2312.html\n",
|
"{file}{cwd}/tests/data/unusual_encodings/gb2312.html\n",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
||||||
|
@ -161,7 +161,7 @@ mod passing {
|
||||||
.arg("-C")
|
.arg("-C")
|
||||||
.arg("utf0")
|
.arg("utf0")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}unusual_encodings{s}gb2312.html",
|
"tests{s}data{s}unusual_encodings{s}gb2312.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.output()
|
.output()
|
||||||
|
@ -198,12 +198,12 @@ mod failing {
|
||||||
#[test]
|
#[test]
|
||||||
fn change_iso88591_to_utf8_to_properly_display_html_entities() {
|
fn change_iso88591_to_utf8_to_properly_display_html_entities() {
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let cwd_normalized: String = str!(cwd.to_str().unwrap()).replace("\\", "/");
|
let cwd_normalized: String = cwd.to_str().unwrap().replace("\\", "/");
|
||||||
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
||||||
let out = cmd
|
let out = cmd
|
||||||
.arg("-M")
|
.arg("-M")
|
||||||
.arg(format!(
|
.arg(format!(
|
||||||
"src{s}tests{s}data{s}unusual_encodings{s}iso-8859-1.html",
|
"tests{s}data{s}unusual_encodings{s}iso-8859-1.html",
|
||||||
s = MAIN_SEPARATOR
|
s = MAIN_SEPARATOR
|
||||||
))
|
))
|
||||||
.output()
|
.output()
|
||||||
|
@ -214,7 +214,7 @@ mod failing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&out.stderr),
|
String::from_utf8_lossy(&out.stderr),
|
||||||
format!(
|
format!(
|
||||||
"{file}{cwd}/src/tests/data/unusual_encodings/iso-8859-1.html\n",
|
"{file}{cwd}/tests/data/unusual_encodings/iso-8859-1.html\n",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd_normalized,
|
cwd = cwd_normalized,
|
||||||
)
|
)
|
|
@ -11,8 +11,9 @@ mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::css;
|
use monolith::css;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_input() {
|
fn empty_input() {
|
||||||
|
@ -67,7 +68,7 @@ mod passing {
|
||||||
margin-top: -20px; \
|
margin-top: -20px; \
|
||||||
line-height: -1; \
|
line-height: -1; \
|
||||||
height: calc(100vh - 10pt)",
|
height: calc(100vh - 10pt)",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +100,7 @@ mod passing {
|
||||||
margin-top: -20px; \
|
margin-top: -20px; \
|
||||||
line-height: -1; \
|
line-height: -1; \
|
||||||
height: calc(100vh - 10pt)",
|
height: calc(100vh - 10pt)",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::css;
|
use monolith::css;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn backrgound() {
|
fn backrgound() {
|
||||||
|
@ -64,7 +64,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::css;
|
use monolith::css;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty() {
|
fn empty() {
|
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 296 B |
|
@ -9,12 +9,12 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use html5ever::serialize::{serialize, SerializeOpts};
|
use html5ever::serialize::{serialize, SerializeOpts};
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
let html = "<div>text</div>";
|
let html = "<div>text</div>";
|
||||||
let mut dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let mut dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
dom = html::add_favicon(&dom.document, "I_AM_A_FAVICON_DATA_URL".to_string());
|
dom = html::add_favicon(&dom.document, "I_AM_A_FAVICON_DATA_URL".to_string());
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_input_sha256() {
|
fn empty_input_sha256() {
|
||||||
|
@ -51,7 +51,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_hash() {
|
fn empty_hash() {
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn isolated() {
|
fn isolated() {
|
|
@ -10,7 +10,7 @@ mod passing {
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn http_url() {
|
fn http_url() {
|
|
@ -11,8 +11,9 @@ mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn small_medium_large() {
|
fn small_medium_large() {
|
||||||
|
@ -35,9 +36,7 @@ mod passing {
|
||||||
embedded_css,
|
embedded_css,
|
||||||
format!(
|
format!(
|
||||||
"{} 1x, {} 1.5x, {} 2x",
|
"{} 1x, {} 1.5x, {} 2x",
|
||||||
empty_image!(),
|
EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL,
|
||||||
empty_image!(),
|
|
||||||
empty_image!(),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +60,7 @@ mod passing {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
embedded_css,
|
embedded_css,
|
||||||
format!("{}, {} 1.5x", empty_image!(), empty_image!()),
|
format!("{}, {} 1.5x", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +83,7 @@ mod passing {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
embedded_css,
|
embedded_css,
|
||||||
format!("{} 1x, {} 2x", empty_image!(), empty_image!()),
|
format!("{} 1x, {} 2x", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,9 +108,7 @@ mod passing {
|
||||||
embedded_css,
|
embedded_css,
|
||||||
format!(
|
format!(
|
||||||
"{} 1x, {} 2x, {} 3x",
|
"{} 1x, {} 2x, {} 3x",
|
||||||
empty_image!(),
|
EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL
|
||||||
empty_image!(),
|
|
||||||
empty_image!()
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -130,8 +127,9 @@ mod failing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn trailing_comma() {
|
fn trailing_comma() {
|
||||||
|
@ -152,7 +150,7 @@ mod failing {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
embedded_css,
|
embedded_css,
|
||||||
format!("{} 1x, {} 2x,", empty_image!(), empty_image!()),
|
format!("{} 1x, {} 2x,", EMPTY_IMAGE_DATA_URL, EMPTY_IMAGE_DATA_URL),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn present() {
|
fn present() {
|
||||||
|
@ -19,11 +19,11 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
html::get_base_url(&dom.document),
|
html::get_base_url(&dom.document),
|
||||||
Some(str!("https://musicbrainz.org"))
|
Some("https://musicbrainz.org".to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,11 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
html::get_base_url(&dom.document),
|
html::get_base_url(&dom.document),
|
||||||
Some(str!("https://www.discogs.com/"))
|
Some("https://www.discogs.com/".to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn absent() {
|
fn absent() {
|
||||||
|
@ -67,7 +67,7 @@ mod failing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_base_url(&dom.document), None);
|
assert_eq!(html::get_base_url(&dom.document), None);
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ mod failing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_base_url(&dom.document), None);
|
assert_eq!(html::get_base_url(&dom.document), None);
|
||||||
}
|
}
|
||||||
|
@ -97,8 +97,8 @@ mod failing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_base_url(&dom.document), Some(str!()));
|
assert_eq!(html::get_base_url(&dom.document), Some("".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn meta_content_type() {
|
fn meta_content_type() {
|
||||||
|
@ -19,9 +19,9 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -34,9 +34,9 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -50,9 +50,9 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_charset(&dom.document), Some(str!("utf-8")));
|
assert_eq!(html::get_charset(&dom.document), Some("utf-8".to_string()));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_conflicting_meta_content_type_first() {
|
fn multiple_conflicting_meta_content_type_first() {
|
||||||
|
@ -65,8 +65,8 @@ mod passing {
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
|
|
||||||
assert_eq!(html::get_charset(&dom.document), Some(str!("GB2312")));
|
assert_eq!(html::get_charset(&dom.document), Some("GB2312".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,12 +9,12 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use html5ever::rcdom::{Handle, NodeData};
|
use html5ever::rcdom::{Handle, NodeData};
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn div_two_style_attributes() {
|
fn div_two_style_attributes() {
|
||||||
let html = "<!doctype html><html><head></head><body><DIV STYLE=\"color: blue;\" style=\"display: none;\"></div></body></html>";
|
let html = "<!doctype html><html><head></head><body><DIV STYLE=\"color: blue;\" style=\"display: none;\"></div></body></html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
fn test_walk(node: &Handle, i: &mut i8) {
|
fn test_walk(node: &Handle, i: &mut i8) {
|
||||||
|
@ -35,7 +35,7 @@ mod passing {
|
||||||
} else if node_name == "div" {
|
} else if node_name == "div" {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
html::get_node_attr(node, "style"),
|
html::get_node_attr(node, "style"),
|
||||||
Some(str!("color: blue;"))
|
Some("color: blue;".to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,12 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use html5ever::rcdom::{Handle, NodeData};
|
use html5ever::rcdom::{Handle, NodeData};
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parent_node_names() {
|
fn parent_node_names() {
|
||||||
let html = "<!doctype html><html><HEAD></HEAD><body><div><P></P></div></body></html>";
|
let html = "<!doctype html><html><HEAD></HEAD><body><div><P></P></div></body></html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
fn test_walk(node: &Handle, i: &mut i8) {
|
fn test_walk(node: &Handle, i: &mut i8) {
|
|
@ -7,12 +7,12 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn icon() {
|
fn icon() {
|
||||||
let html = "<link rel=\"icon\" href=\"\" /><div>text</div>";
|
let html = "<link rel=\"icon\" href=\"\" /><div>text</div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let res: bool = html::has_favicon(&dom.document);
|
let res: bool = html::has_favicon(&dom.document);
|
||||||
|
|
||||||
assert!(res);
|
assert!(res);
|
||||||
|
@ -21,7 +21,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn shortcut_icon() {
|
fn shortcut_icon() {
|
||||||
let html = "<link rel=\"shortcut icon\" href=\"\" /><div>text</div>";
|
let html = "<link rel=\"shortcut icon\" href=\"\" /><div>text</div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let res: bool = html::has_favicon(&dom.document);
|
let res: bool = html::has_favicon(&dom.document);
|
||||||
|
|
||||||
assert!(res);
|
assert!(res);
|
||||||
|
@ -37,12 +37,12 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn absent() {
|
fn absent() {
|
||||||
let html = "<div>text</div>";
|
let html = "<div>text</div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let res: bool = html::has_favicon(&dom.document);
|
let res: bool = html::has_favicon(&dom.document);
|
||||||
|
|
||||||
assert!(!res);
|
assert!(!res);
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn icon() {
|
fn icon() {
|
||||||
|
@ -34,7 +34,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mask_icon() {
|
fn mask_icon() {
|
|
@ -7,17 +7,17 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn div_as_root_element() {
|
fn div_as_root_element() {
|
||||||
let html = "<div><script src=\"some.js\"></script></div>";
|
let html = "<div><script src=\"some.js\"></script></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let options = Options::default();
|
let options = Options::default();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&html::serialize_document(dom, str!(), &options)),
|
String::from_utf8_lossy(&html::serialize_document(dom, "".to_string(), &options)),
|
||||||
"<html><head></head><body><div><script src=\"some.js\"></script></div></body></html>"
|
"<html><head></head><body><div><script src=\"some.js\"></script></div></body></html>"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -28,14 +28,14 @@ mod passing {
|
||||||
<link rel=\"something\" href=\"some.css\" />\
|
<link rel=\"something\" href=\"some.css\" />\
|
||||||
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src https:\">\
|
<meta http-equiv=\"Content-Security-Policy\" content=\"default-src https:\">\
|
||||||
<div><script src=\"some.js\"></script></div>";
|
<div><script src=\"some.js\"></script></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
options.isolate = true;
|
options.isolate = true;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&html::serialize_document(
|
String::from_utf8_lossy(&html::serialize_document(
|
||||||
dom,
|
dom,
|
||||||
str!(),
|
"".to_string(),
|
||||||
&options
|
&options
|
||||||
)),
|
)),
|
||||||
"<html>\
|
"<html>\
|
||||||
|
@ -60,12 +60,12 @@ mod passing {
|
||||||
<title>Unstyled document</title>\
|
<title>Unstyled document</title>\
|
||||||
<link rel=\"stylesheet\" href=\"main.css\"/>\
|
<link rel=\"stylesheet\" href=\"main.css\"/>\
|
||||||
<div style=\"display: none;\"></div>";
|
<div style=\"display: none;\"></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
options.no_css = true;
|
options.no_css = true;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&html::serialize_document(dom, str!(), &options)),
|
String::from_utf8_lossy(&html::serialize_document(dom, "".to_string(), &options)),
|
||||||
"<!DOCTYPE html>\
|
"<!DOCTYPE html>\
|
||||||
<html>\
|
<html>\
|
||||||
<head>\
|
<head>\
|
||||||
|
@ -84,14 +84,14 @@ mod passing {
|
||||||
<title>Frameless document</title>\
|
<title>Frameless document</title>\
|
||||||
<link rel=\"something\"/>\
|
<link rel=\"something\"/>\
|
||||||
<div><script src=\"some.js\"></script></div>";
|
<div><script src=\"some.js\"></script></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
options.no_frames = true;
|
options.no_frames = true;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&html::serialize_document(
|
String::from_utf8_lossy(&html::serialize_document(
|
||||||
dom,
|
dom,
|
||||||
str!(),
|
"".to_string(),
|
||||||
&options
|
&options
|
||||||
)),
|
)),
|
||||||
"<!DOCTYPE html>\
|
"<!DOCTYPE html>\
|
||||||
|
@ -117,7 +117,7 @@ mod passing {
|
||||||
<img style=\"width: 100%;\" src=\"some.png\" />\
|
<img style=\"width: 100%;\" src=\"some.png\" />\
|
||||||
<iframe src=\"some.html\"></iframe>\
|
<iframe src=\"some.html\"></iframe>\
|
||||||
</div>";
|
</div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
options.isolate = true;
|
options.isolate = true;
|
||||||
options.no_css = true;
|
options.no_css = true;
|
||||||
|
@ -129,7 +129,7 @@ mod passing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
String::from_utf8_lossy(&html::serialize_document(
|
String::from_utf8_lossy(&html::serialize_document(
|
||||||
dom,
|
dom,
|
||||||
str!(),
|
"".to_string(),
|
||||||
&options
|
&options
|
||||||
)),
|
)),
|
||||||
"<!DOCTYPE html>\
|
"<!DOCTYPE html>\
|
|
@ -9,12 +9,12 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use html5ever::rcdom::{Handle, NodeData};
|
use html5ever::rcdom::{Handle, NodeData};
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn html_lang_and_body_style() {
|
fn html_lang_and_body_style() {
|
||||||
let html = "<!doctype html><html lang=\"en\"><head></head><body></body></html>";
|
let html = "<!doctype html><html lang=\"en\"><head></head><body></body></html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
fn test_walk(node: &Handle, i: &mut i8) {
|
fn test_walk(node: &Handle, i: &mut i8) {
|
||||||
|
@ -31,23 +31,23 @@ mod passing {
|
||||||
let node_name = name.local.as_ref().to_string();
|
let node_name = name.local.as_ref().to_string();
|
||||||
|
|
||||||
if node_name == "html" {
|
if node_name == "html" {
|
||||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("en")));
|
assert_eq!(html::get_node_attr(node, "lang"), Some("en".to_string()));
|
||||||
|
|
||||||
html::set_node_attr(node, "lang", Some(str!("de")));
|
html::set_node_attr(node, "lang", Some("de".to_string()));
|
||||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("de")));
|
assert_eq!(html::get_node_attr(node, "lang"), Some("de".to_string()));
|
||||||
|
|
||||||
html::set_node_attr(node, "lang", None);
|
html::set_node_attr(node, "lang", None);
|
||||||
assert_eq!(html::get_node_attr(node, "lang"), None);
|
assert_eq!(html::get_node_attr(node, "lang"), None);
|
||||||
|
|
||||||
html::set_node_attr(node, "lang", Some(str!("")));
|
html::set_node_attr(node, "lang", Some("".to_string()));
|
||||||
assert_eq!(html::get_node_attr(node, "lang"), Some(str!("")));
|
assert_eq!(html::get_node_attr(node, "lang"), Some("".to_string()));
|
||||||
} else if node_name == "body" {
|
} else if node_name == "body" {
|
||||||
assert_eq!(html::get_node_attr(node, "style"), None);
|
assert_eq!(html::get_node_attr(node, "style"), None);
|
||||||
|
|
||||||
html::set_node_attr(node, "style", Some(str!("display: none;")));
|
html::set_node_attr(node, "style", Some("display: none;".to_string()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
html::get_node_attr(node, "style"),
|
html::get_node_attr(node, "style"),
|
||||||
Some(str!("display: none;"))
|
Some("display: none;".to_string())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn body_background() {
|
fn body_background() {
|
||||||
let html = "<!doctype html><html lang=\"en\"><head></head><body background=\"1\" background=\"2\"></body></html>";
|
let html = "<!doctype html><html lang=\"en\"><head></head><body background=\"1\" background=\"2\"></body></html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
fn test_walk(node: &Handle, i: &mut i8) {
|
fn test_walk(node: &Handle, i: &mut i8) {
|
||||||
|
@ -84,7 +84,10 @@ mod passing {
|
||||||
let node_name = name.local.as_ref().to_string();
|
let node_name = name.local.as_ref().to_string();
|
||||||
|
|
||||||
if node_name == "body" {
|
if node_name == "body" {
|
||||||
assert_eq!(html::get_node_attr(node, "background"), Some(str!("1")));
|
assert_eq!(
|
||||||
|
html::get_node_attr(node, "background"),
|
||||||
|
Some("1".to_string())
|
||||||
|
);
|
||||||
|
|
||||||
html::set_node_attr(node, "background", None);
|
html::set_node_attr(node, "background", None);
|
||||||
assert_eq!(html::get_node_attr(node, "background"), None);
|
assert_eq!(html::get_node_attr(node, "background"), None);
|
|
@ -12,15 +12,16 @@ mod passing {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::html;
|
use monolith::html;
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
use monolith::url::EMPTY_IMAGE_DATA_URL;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
let html: &str = "<div><P></P></div>";
|
let html: &str = "<div><P></P></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
|
|
||||||
let mut options = Options::default();
|
let mut options = Options::default();
|
||||||
|
@ -42,7 +43,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn ensure_no_recursive_iframe() {
|
fn ensure_no_recursive_iframe() {
|
||||||
let html = "<div><P></P><iframe src=\"\"></iframe></div>";
|
let html = "<div><P></P><iframe src=\"\"></iframe></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn ensure_no_recursive_frame() {
|
fn ensure_no_recursive_frame() {
|
||||||
let html = "<frameset><frame src=\"\"></frameset>";
|
let html = "<frameset><frame src=\"\"></frameset>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -93,7 +94,7 @@ mod passing {
|
||||||
<style>html{background-color: #000;}</style>\
|
<style>html{background-color: #000;}</style>\
|
||||||
<div style=\"display: none;\"></div>\
|
<div style=\"display: none;\"></div>\
|
||||||
";
|
";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ mod passing {
|
||||||
fn no_images() {
|
fn no_images() {
|
||||||
let html = "<link rel=\"icon\" href=\"favicon.ico\">\
|
let html = "<link rel=\"icon\" href=\"favicon.ico\">\
|
||||||
<div><img src=\"http://localhost/assets/mono_lisa.png\" /></div>";
|
<div><img src=\"http://localhost/assets/mono_lisa.png\" /></div>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ mod passing {
|
||||||
</div>\
|
</div>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>",
|
</html>",
|
||||||
empty_image = empty_image!()
|
empty_image = EMPTY_IMAGE_DATA_URL
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -166,7 +167,7 @@ mod passing {
|
||||||
fn no_body_background_images() {
|
fn no_body_background_images() {
|
||||||
let html =
|
let html =
|
||||||
"<body background=\"no/such/image.png\" background=\"no/such/image2.png\"></body>";
|
"<body background=\"no/such/image.png\" background=\"no/such/image2.png\"></body>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -190,7 +191,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn no_frames() {
|
fn no_frames() {
|
||||||
let html = "<frameset><frame src=\"http://trackbook.com\"></frameset>";
|
let html = "<frameset><frame src=\"http://trackbook.com\"></frameset>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -222,7 +223,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn no_iframes() {
|
fn no_iframes() {
|
||||||
let html = "<iframe src=\"http://trackbook.com\"></iframe>";
|
let html = "<iframe src=\"http://trackbook.com\"></iframe>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -258,7 +259,7 @@ mod passing {
|
||||||
<script>alert(1)</script>\
|
<script>alert(1)</script>\
|
||||||
</div>\
|
</div>\
|
||||||
";
|
";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -293,7 +294,7 @@ mod passing {
|
||||||
fn keeps_integrity_for_unfamiliar_links() {
|
fn keeps_integrity_for_unfamiliar_links() {
|
||||||
let html = "<title>Has integrity</title>\
|
let html = "<title>Has integrity</title>\
|
||||||
<link integrity=\"sha384-12345\" rel=\"something\" href=\"https://some-site.com/some-file.ext\" />";
|
<link integrity=\"sha384-12345\" rel=\"something\" href=\"https://some-site.com/some-file.ext\" />";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ mod passing {
|
||||||
<link integrity=\"\" rel=\"stylesheet\" href=\"data:;\"/>\
|
<link integrity=\"\" rel=\"stylesheet\" href=\"data:;\"/>\
|
||||||
<script integrity=\"\" src=\"some.js\"></script>\
|
<script integrity=\"\" src=\"some.js\"></script>\
|
||||||
";
|
";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -366,7 +367,7 @@ mod passing {
|
||||||
<link integrity=\"sha384-123\" rel=\"something\" href=\"data:;\"/>\
|
<link integrity=\"sha384-123\" rel=\"something\" href=\"data:;\"/>\
|
||||||
<script integrity=\"sha384-456\" src=\"some.js\"></script>\
|
<script integrity=\"sha384-456\" src=\"some.js\"></script>\
|
||||||
";
|
";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -410,7 +411,7 @@ mod passing {
|
||||||
</body>\
|
</body>\
|
||||||
</html>\
|
</html>\
|
||||||
";
|
";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -452,7 +453,7 @@ mod passing {
|
||||||
</noscript>\
|
</noscript>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>";
|
</html>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
||||||
|
@ -480,7 +481,7 @@ mod passing {
|
||||||
</noscript>\
|
</noscript>\
|
||||||
</body>\
|
</body>\
|
||||||
</html>",
|
</html>",
|
||||||
empty_image!(),
|
EMPTY_IMAGE_DATA_URL,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -488,7 +489,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn preserves_script_type_json() {
|
fn preserves_script_type_json() {
|
||||||
let html = "<script id=\"data\" type=\"application/json\">{\"mono\":\"lith\"}</script>";
|
let html = "<script id=\"data\" type=\"application/json\">{\"mono\":\"lith\"}</script>";
|
||||||
let dom = html::html_to_dom(&html.as_bytes().to_vec(), str!());
|
let dom = html::html_to_dom(&html.as_bytes().to_vec(), "".to_string());
|
||||||
let url: Url = Url::parse("http://localhost").unwrap();
|
let url: Url = Url::parse("http://localhost").unwrap();
|
||||||
let cache = &mut HashMap::new();
|
let cache = &mut HashMap::new();
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::js;
|
use monolith::js;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn onblur_camelcase() {
|
fn onblur_camelcase() {
|
||||||
|
@ -34,7 +34,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::js;
|
use monolith::js;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn href() {
|
fn href() {
|
|
@ -2,7 +2,7 @@ mod cli;
|
||||||
mod css;
|
mod css;
|
||||||
mod html;
|
mod html;
|
||||||
mod js;
|
mod js;
|
||||||
mod macros;
|
// mod macros;
|
||||||
mod opts;
|
mod opts;
|
||||||
mod url;
|
mod url;
|
||||||
mod utils;
|
mod utils;
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults() {
|
fn defaults() {
|
||||||
|
@ -24,12 +24,12 @@ mod passing {
|
||||||
assert_eq!(options.no_js, false);
|
assert_eq!(options.no_js, false);
|
||||||
assert_eq!(options.insecure, false);
|
assert_eq!(options.insecure, false);
|
||||||
assert_eq!(options.no_metadata, false);
|
assert_eq!(options.no_metadata, false);
|
||||||
assert_eq!(options.output, str!());
|
assert_eq!(options.output, "".to_string());
|
||||||
assert_eq!(options.silent, false);
|
assert_eq!(options.silent, false);
|
||||||
assert_eq!(options.timeout, 0);
|
assert_eq!(options.timeout, 0);
|
||||||
assert_eq!(options.user_agent, None);
|
assert_eq!(options.user_agent, None);
|
||||||
assert_eq!(options.no_video, false);
|
assert_eq!(options.no_video, false);
|
||||||
|
|
||||||
assert_eq!(options.target, str!());
|
assert_eq!(options.target, "".to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn preserve_original() {
|
fn preserve_original() {
|
|
@ -9,7 +9,7 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_string_with_specific_media_type() {
|
fn encode_string_with_specific_media_type() {
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mailto() {
|
fn mailto() {
|
||||||
|
@ -80,7 +80,7 @@ mod passing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod failing {
|
mod failing {
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn url_with_no_protocol() {
|
fn url_with_no_protocol() {
|
|
@ -9,7 +9,7 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_text_html_base64() {
|
fn parse_text_html_base64() {
|
||||||
|
@ -96,7 +96,7 @@ mod passing {
|
||||||
mod failing {
|
mod failing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_data_url() {
|
fn empty_data_url() {
|
|
@ -7,14 +7,15 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_unicode_characters() {
|
fn decode_unicode_characters() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
url::percent_decode(str!(
|
url::percent_decode(
|
||||||
"%E6%A4%9C%E3%83%92%E3%83%A0%E8%A7%A3%E5%A1%97%E3%82%83%E3%83%83%20%3D%20%E3%82%B5"
|
"%E6%A4%9C%E3%83%92%E3%83%A0%E8%A7%A3%E5%A1%97%E3%82%83%E3%83%83%20%3D%20%E3%82%B5"
|
||||||
)),
|
.to_string()
|
||||||
|
),
|
||||||
"検ヒム解塗ゃッ = サ"
|
"検ヒム解塗ゃッ = サ"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +23,7 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn decode_file_url() {
|
fn decode_file_url() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
url::percent_decode(str!("file:///tmp/space%20here/test%231.html")),
|
url::percent_decode("file:///tmp/space%20here/test%231.html".to_string()),
|
||||||
"file:///tmp/space here/test#1.html"
|
"file:///tmp/space here/test#1.html"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,9 +31,10 @@ mod passing {
|
||||||
#[test]
|
#[test]
|
||||||
fn plus_sign() {
|
fn plus_sign() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
url::percent_decode(str!(
|
url::percent_decode(
|
||||||
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
||||||
)),
|
.to_string()
|
||||||
|
),
|
||||||
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
"fonts.somewhere.com/css?family=Open+Sans:300,400,400italic,600,600italic"
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn apostrophe() {
|
fn apostrophe() {
|
||||||
assert_eq!(url::percent_encode(str!("'")), "%27");
|
assert_eq!(url::percent_encode("'".to_string()), "%27");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic_httsp_relative() {
|
fn basic_httsp_relative() {
|
||||||
|
@ -211,7 +211,7 @@ mod passing {
|
||||||
mod failing {
|
mod failing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn from_data_url_to_url_with_no_protocol() {
|
fn from_data_url_to_url_with_no_protocol() {
|
|
@ -9,7 +9,7 @@
|
||||||
mod passing {
|
mod passing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn image_gif87() {
|
fn image_gif87() {
|
||||||
|
@ -188,7 +188,7 @@ mod passing {
|
||||||
mod failing {
|
mod failing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unknown_media_type() {
|
fn unknown_media_type() {
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zero() {
|
fn zero() {
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod passing {
|
mod passing {
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn text_plain_utf8() {
|
fn text_plain_utf8() {
|
|
@ -12,9 +12,9 @@ mod passing {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
use crate::url;
|
use monolith::url;
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_data_url() {
|
fn read_data_url() {
|
||||||
|
@ -63,13 +63,13 @@ mod passing {
|
||||||
cache,
|
cache,
|
||||||
&client,
|
&client,
|
||||||
&Url::parse(&format!(
|
&Url::parse(&format!(
|
||||||
"{file}{cwd}/src/tests/data/basic/local-file.html",
|
"{file}{cwd}/tests/data/basic/local-file.html",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd.to_str().unwrap()
|
cwd = cwd.to_str().unwrap()
|
||||||
))
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
&Url::parse(&format!(
|
&Url::parse(&format!(
|
||||||
"{file}{cwd}/src/tests/data/basic/local-script.js",
|
"{file}{cwd}/tests/data/basic/local-script.js",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd.to_str().unwrap()
|
cwd = cwd.to_str().unwrap()
|
||||||
))
|
))
|
||||||
|
@ -84,7 +84,7 @@ mod passing {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
final_url,
|
final_url,
|
||||||
Url::parse(&format!(
|
Url::parse(&format!(
|
||||||
"{file}{cwd}/src/tests/data/basic/local-script.js",
|
"{file}{cwd}/tests/data/basic/local-script.js",
|
||||||
file = file_url_protocol,
|
file = file_url_protocol,
|
||||||
cwd = cwd.to_str().unwrap()
|
cwd = cwd.to_str().unwrap()
|
||||||
))
|
))
|
||||||
|
@ -106,8 +106,8 @@ mod failing {
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::opts::Options;
|
use monolith::opts::Options;
|
||||||
use crate::utils;
|
use monolith::utils;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_local_file_with_data_url_parent() {
|
fn read_local_file_with_data_url_parent() {
|
Loading…
Reference in a new issue