use std::borrow::Cow;
use std::path::{Path, PathBuf};
use crate::error::ConversionError;
use crate::format::InputFormat;
#[derive(Debug, Clone)]
pub struct SourceDocument {
pub name: String,
pub format: InputFormat,
pub bytes: Vec<u8>,
pub extension: Option<String>,
pub path: Option<PathBuf>,
pub base_url: Option<String>,
pub encoding: Option<String>,
pub media_type: Option<String>,
}
impl SourceDocument {
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConversionError> {
let path = path.as_ref();
let bytes = std::fs::read(path)?;
Self::from_path_and_bytes(path, bytes)
}
pub(crate) fn from_path_and_bytes(
path: &Path,
bytes: Vec<u8>,
) -> Result<Self, ConversionError> {
let ext = path
.extension()
.and_then(|e| e.to_str())
.map(str::to_ascii_lowercase);
let format = match ext.as_deref().and_then(InputFormat::from_extension) {
Some(f) => f,
None => crate::sniff::detect_any(&bytes)
.or_else(|| crate::sniff::looks_like_text(&bytes).then_some(InputFormat::Text))
.ok_or_else(|| ConversionError::UnknownFormat {
hint: match &ext {
Some(e) => format!(
"unrecognized extension '.{e}' and the content is neither a known \
signature nor text"
),
None => format!(
"no extension on {} and the content is neither a known signature \
nor text",
path.display()
),
},
})?,
};
let format = refine_format(format, &bytes);
let name = path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("document")
.to_string();
Ok(Self {
name,
format,
bytes,
extension: ext,
path: Some(path.to_path_buf()),
base_url: None,
encoding: None,
media_type: None,
})
}
pub fn from_named_bytes(
name: &str,
bytes: Vec<u8>,
media_type: Option<&str>,
) -> Result<Self, ConversionError> {
let path = Path::new(name);
let ext = path.extension().and_then(|e| e.to_str());
let format = ext
.and_then(InputFormat::from_extension)
.or_else(|| media_type.and_then(InputFormat::from_mime))
.or_else(|| crate::sniff::detect_any(&bytes))
.or_else(|| crate::sniff::looks_like_text(&bytes).then_some(InputFormat::Text))
.ok_or_else(|| ConversionError::UnknownFormat {
hint: match (ext, media_type) {
(Some(e), _) => format!("unrecognized extension '.{e}'"),
(None, Some(m)) => format!(
"cannot determine the format of '{name}': no file extension, \
media type '{m}' is not one docling converts, and the content \
matches no known signature"
),
(None, None) => format!(
"cannot determine the format of '{name}': no file extension, \
no media type, and the content matches no known signature"
),
},
})?;
let stem = path
.file_stem()
.and_then(|s| s.to_str())
.filter(|s| !s.is_empty())
.unwrap_or("document")
.to_string();
let format = refine_format(format, &bytes);
let mut doc = Self::from_bytes(stem, format, bytes);
doc.extension = ext.map(str::to_ascii_lowercase);
doc.media_type = media_type.map(str::to_string);
Ok(doc)
}
pub fn from_reader<R: std::io::Read>(
name: &str,
mut reader: R,
media_type: Option<&str>,
) -> Result<Self, ConversionError> {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes)?;
Self::from_named_bytes(name, bytes, media_type)
}
#[cfg(feature = "fetch-url")]
pub fn from_url(
url: &str,
policy: &crate::fetch::FetchPolicy,
) -> Result<Self, ConversionError> {
let fetched = crate::fetch::fetch(url, policy)?;
let name = crate::fetch::fetched_name(&fetched.url, fetched.content_disposition.as_deref());
Ok(
Self::from_named_bytes(&name, fetched.bytes, fetched.content_type.as_deref())?
.with_base_url(fetched.url),
)
}
pub fn from_bytes(name: impl Into<String>, format: InputFormat, bytes: Vec<u8>) -> Self {
let name = name.into();
let extension = Path::new(&name)
.extension()
.and_then(|e| e.to_str())
.map(str::to_ascii_lowercase);
Self {
name,
format,
bytes,
extension,
path: None,
base_url: None,
encoding: None,
media_type: None,
}
}
pub fn with_media_type(mut self, media_type: Option<String>) -> Self {
self.media_type = media_type;
self
}
pub fn with_encoding(mut self, label: Option<String>) -> Self {
self.encoding = label;
self
}
pub fn with_base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = Some(url.into());
self
}
pub fn with_source_uri(mut self, uri: &str) -> Self {
let lower = uri.trim().to_ascii_lowercase();
if lower.starts_with("http://") || lower.starts_with("https://") {
return self.with_base_url(uri.trim());
}
match local_source_path(uri.trim()) {
Ok(path) => self.path = Some(path),
Err(why) => eprintln!("docling: source_uri '{uri}' ignored: {why}"),
}
self
}
pub fn base_dir(&self) -> Option<&Path> {
self.path.as_deref().and_then(Path::parent).map(|p| {
if p.as_os_str().is_empty() {
Path::new(".")
} else {
p
}
})
}
pub fn text(&self) -> Result<Cow<'_, str>, ConversionError> {
match &self.encoding {
Some(label) => decode_text_as(&self.bytes, label),
None => decode_text(&self.bytes),
}
}
}
pub(crate) fn decode_text_as<'a>(
bytes: &'a [u8],
label: &str,
) -> Result<Cow<'a, str>, ConversionError> {
if let Some(codec) = unicode_codec(label) {
return decode_unicode_as(bytes, codec, label);
}
let encoding = lookup_encoding(label).ok_or_else(|| {
ConversionError::Parse(format!(
"unknown character encoding {label:?}: use a WHATWG encoding label such as \
utf-8, windows-1252, latin1, shift_jis, euc-jp, gbk, big5, euc-kr or koi8-r"
))
})?;
let (text, had_errors) = encoding.decode_with_bom_removal(bytes);
if had_errors {
return Err(ConversionError::Parse(format!(
"input is not valid {}: it cannot be decoded with the requested encoding {label:?}",
encoding.name()
)));
}
Ok(text)
}
#[derive(Clone, Copy)]
enum UnicodeCodec {
Utf8,
Utf16(Option<bool>),
Utf32(Option<bool>),
}
fn unicode_codec(label: &str) -> Option<UnicodeCodec> {
let l = label.trim().to_ascii_lowercase().replace('_', "-");
let key = l.replace('-', "");
Some(match key.as_str() {
"utf8" | "u8" | "utf" | "cp65001" | "utf8sig" => UnicodeCodec::Utf8,
"utf16" | "u16" => UnicodeCodec::Utf16(None),
"utf16le" => UnicodeCodec::Utf16(Some(true)),
"utf16be" => UnicodeCodec::Utf16(Some(false)),
"utf32" | "u32" => UnicodeCodec::Utf32(None),
"utf32le" => UnicodeCodec::Utf32(Some(true)),
"utf32be" => UnicodeCodec::Utf32(Some(false)),
_ => return None,
})
}
fn decode_unicode_as<'a>(
bytes: &'a [u8],
codec: UnicodeCodec,
label: &str,
) -> Result<Cow<'a, str>, ConversionError> {
let invalid = |name: &str| {
ConversionError::Parse(format!(
"input is not valid {name}: it cannot be decoded with the requested encoding {label:?}"
))
};
let text: Cow<'a, str> = match codec {
UnicodeCodec::Utf8 => {
let rest = bytes.strip_prefix(b"\xef\xbb\xbf").unwrap_or(bytes);
Cow::Borrowed(std::str::from_utf8(rest).map_err(|_| invalid("UTF-8"))?)
}
UnicodeCodec::Utf16(order) => {
let (le, rest) = match (order, bytes) {
(None, [0xfe, 0xff, rest @ ..]) => (false, rest),
(None, [0xff, 0xfe, rest @ ..]) => (true, rest),
(None, _) => (true, bytes),
(Some(le), _) => (le, bytes),
};
let encoding = if le {
encoding_rs::UTF_16LE
} else {
encoding_rs::UTF_16BE
};
let text = encoding
.decode_without_bom_handling_and_without_replacement(rest)
.ok_or_else(|| invalid(encoding.name()))?;
Cow::Owned(text.into_owned())
}
UnicodeCodec::Utf32(order) => {
let (le, rest) = match (order, bytes) {
(None, [0x00, 0x00, 0xfe, 0xff, rest @ ..]) => (false, rest),
(None, [0xff, 0xfe, 0x00, 0x00, rest @ ..]) => (true, rest),
(None, _) => (true, bytes),
(Some(le), _) => (le, bytes),
};
let name = if le { "UTF-32LE" } else { "UTF-32BE" };
decode_utf32(rest, le).map_err(|_| invalid(name))?
}
};
Ok(match text {
Cow::Borrowed(t) => Cow::Borrowed(t.strip_prefix('\u{feff}').unwrap_or(t)),
Cow::Owned(t) => match t.strip_prefix('\u{feff}') {
Some(rest) => Cow::Owned(rest.to_string()),
None => Cow::Owned(t),
},
})
}
pub(crate) fn lookup_encoding(label: &str) -> Option<&'static encoding_rs::Encoding> {
let label = label.trim();
let dashed = label.replace('_', "-").to_ascii_lowercase();
encoding_rs::Encoding::for_label(label.as_bytes())
.or_else(|| encoding_rs::Encoding::for_label(dashed.as_bytes()))
.or_else(|| {
let alias = match dashed.as_str() {
"latin-1" | "iso8859-1" | "iso-latin-1" => "latin1",
"cp932" | "ms932" | "sjis" => "shift_jis",
"mac-roman" | "macroman" => "macintosh",
"cp1361" | "johab" | "euc-tw" => return None,
_ => return None,
};
encoding_rs::Encoding::for_label(alias.as_bytes())
})
}
pub(crate) fn decode_text(bytes: &[u8]) -> Result<Cow<'_, str>, ConversionError> {
let bom_error = |codec: &str, detail: &str| {
ConversionError::Parse(format!(
"could not decode the document with the BOM-detected encoding '{codec}': {detail}"
))
};
if let Some(rest) = bytes.strip_prefix(&[0xff, 0xfe, 0x00, 0x00]) {
return decode_utf32(rest, true).map_err(|e| bom_error("utf-32", &e.to_string()));
}
if let Some(rest) = bytes.strip_prefix(&[0x00, 0x00, 0xfe, 0xff]) {
return decode_utf32(rest, false).map_err(|e| bom_error("utf-32", &e.to_string()));
}
if let Some(rest) = bytes.strip_prefix(b"\xef\xbb\xbf") {
return std::str::from_utf8(rest)
.map(Cow::Borrowed)
.map_err(|e| bom_error("utf-8-sig", &e.to_string()));
}
if bytes.starts_with(&[0xff, 0xfe]) || bytes.starts_with(&[0xfe, 0xff]) {
let (text, _, malformed) = encoding_rs::UTF_16LE.decode(bytes);
if malformed {
return Err(bom_error("utf-16", "the input is not valid UTF-16"));
}
return Ok(Cow::Owned(text.into_owned()));
}
match std::str::from_utf8(bytes) {
Ok(text) => Ok(Cow::Borrowed(text)),
Err(utf8_error) => {
let coverage = utf8_high_byte_coverage(bytes);
if coverage >= 0.5 {
return Err(ConversionError::Parse(format!(
"input is not valid UTF-8 ({utf8_error}), but {:.0}% of its non-ASCII \
bytes still form well-formed UTF-8 sequences, so it reads as damaged \
UTF-8 rather than as another encoding; decoding it as windows-1252 \
would turn the damage into text that looks fine and is not",
coverage * 100.0
)));
}
if let Some((encoding, text)) = guess_legacy_encoding(bytes) {
eprintln!(
"warning: input is not UTF-8; it reads as {} and was decoded as that — pass \
encoding=… if it is another encoding",
encoding.name()
);
return Ok(Cow::Owned(text));
}
if bytes
.iter()
.any(|b| matches!(b, 0x81 | 0x8d | 0x8f | 0x90 | 0x9d))
{
return Err(ConversionError::Parse(
"input is neither UTF-8 nor windows-1252, and its encoding is not \
declared, so it cannot be decoded reliably"
.into(),
));
}
eprintln!(
"warning: input is not UTF-8; decoded it as windows-1252 — text in any \
other single-byte or multi-byte encoding will be wrong"
);
let (text, _) = encoding_rs::WINDOWS_1252.decode_without_bom_handling(bytes);
Ok(Cow::Owned(text.into_owned()))
}
}
}
fn guess_legacy_encoding(bytes: &[u8]) -> Option<(&'static encoding_rs::Encoding, String)> {
use encoding_rs::*;
let mut detector = chardetng::EncodingDetector::new(chardetng::Iso2022JpDetection::Deny);
detector.feed(bytes, true);
let encoding = detector.guess(None, chardetng::Utf8Detection::Deny);
const NON_LATIN: &[&Encoding] = &[
SHIFT_JIS,
EUC_JP,
GBK,
GB18030,
BIG5,
EUC_KR,
KOI8_R,
KOI8_U,
IBM866,
WINDOWS_1251,
ISO_8859_5,
WINDOWS_1253,
ISO_8859_7,
WINDOWS_1255,
ISO_8859_8,
ISO_8859_8_I,
WINDOWS_1256,
ISO_8859_6,
WINDOWS_874,
];
if !NON_LATIN.contains(&encoding) {
return None;
}
let (text, malformed) = encoding.decode_without_bom_handling(bytes);
if malformed {
return None;
}
let non_ascii: Vec<char> = text.chars().filter(|c| !c.is_ascii()).collect();
let letters = non_ascii
.iter()
.filter(|c| c.is_alphabetic() || c.is_numeric())
.count();
if non_ascii.len() < 3 || letters * 5 < non_ascii.len() * 4 {
return None;
}
Some((encoding, text.into_owned()))
}
pub(crate) fn decode_utf32(
rest: &[u8],
little_endian: bool,
) -> Result<Cow<'static, str>, ConversionError> {
if !rest.len().is_multiple_of(4) {
return Err(ConversionError::Parse("truncated UTF-32 input".into()));
}
rest.chunks_exact(4)
.map(|c| {
let b = [c[0], c[1], c[2], c[3]];
let u = if little_endian {
u32::from_le_bytes(b)
} else {
u32::from_be_bytes(b)
};
char::from_u32(u)
.ok_or_else(|| ConversionError::Parse(format!("invalid UTF-32 code point {u:#x}")))
})
.collect::<Result<String, _>>()
.map(Cow::Owned)
}
fn utf8_high_byte_coverage(raw: &[u8]) -> f64 {
let (mut high, mut covered, mut i) = (0usize, 0usize, 0usize);
while i < raw.len() {
let lead = raw[i];
if lead < 0x80 {
i += 1;
continue;
}
let len = match lead {
0xc2..=0xdf => 2,
0xe0..=0xef => 3,
0xf0..=0xf4 => 4,
_ => 0,
};
let well_formed = len > 0
&& raw
.get(i..i + len)
.is_some_and(|chunk| std::str::from_utf8(chunk).is_ok());
if well_formed {
high += len;
covered += len;
i += len;
} else {
high += 1;
i += 1;
}
}
if high == 0 {
0.0
} else {
covered as f64 / high as f64
}
}
#[cfg(test)]
mod decode_tests {
use super::{decode_text, decode_text_as};
#[test]
fn explicit_encoding_decodes_strictly() {
let sjis = b"\x93\xfa\x96\x7b";
assert_eq!(decode_text_as(sjis, "shift_jis").unwrap(), "日本");
assert_eq!(decode_text_as(sjis, "Shift_JIS").unwrap(), "日本");
assert_eq!(decode_text_as(sjis, "cp932").unwrap(), "日本");
let koi = b"\xf0\xd2\xc9\xd7\xc5\xd4";
assert_eq!(decode_text_as(koi, "koi8-r").unwrap(), "Привет");
assert_eq!(decode_text_as(koi, "koi8_r").unwrap(), "Привет");
assert_eq!(decode_text_as(b"caf\xe9", "latin-1").unwrap(), "caf\u{e9}");
assert_eq!(decode_text_as(b"\xef\xbb\xbfa", "utf-8").unwrap(), "a");
assert!(matches!(
decode_text_as(b"plain", "utf-8").unwrap(),
std::borrow::Cow::Borrowed(_)
));
let err = decode_text_as(b"caf\xe9", "utf-8").unwrap_err().to_string();
assert!(err.contains("UTF-8"), "{err}");
let err = decode_text_as(b"x", "klingon-1").unwrap_err().to_string();
assert!(err.contains("unknown character encoding"), "{err}");
}
#[test]
fn unicode_codec_aliases_drop_the_mark() {
let enc16 = |s: &str, le: bool| -> Vec<u8> {
s.encode_utf16()
.flat_map(|u| if le { u.to_le_bytes() } else { u.to_be_bytes() })
.collect()
};
let enc32 = |s: &str, le: bool| -> Vec<u8> {
s.chars()
.flat_map(|c| {
let u = c as u32;
if le {
u.to_le_bytes()
} else {
u.to_be_bytes()
}
})
.collect()
};
let text = "# Title\nHello";
let utf8_bom = [&b"\xef\xbb\xbf"[..], text.as_bytes()].concat();
for label in ["utf-8", "utf8", "UTF-8", "utf_8", "UTF8", "u8", "utf-8-sig"] {
assert_eq!(decode_text_as(&utf8_bom, label).unwrap(), text, "{label}");
}
let cases: [(&str, Vec<u8>); 4] = [
(
"utf-16-le",
[&[0xff, 0xfe][..], &enc16(text, true)].concat(),
),
(
"utf-16-be",
[&[0xfe, 0xff][..], &enc16(text, false)].concat(),
),
(
"utf-32-le",
[&[0xff, 0xfe, 0, 0][..], &enc32(text, true)].concat(),
),
(
"utf-32-be",
[&[0, 0, 0xfe, 0xff][..], &enc32(text, false)].concat(),
),
];
for (label, bytes) in &cases {
assert_eq!(decode_text_as(bytes, label).unwrap(), text, "{label}");
let python = label.replace('-', "_");
assert_eq!(decode_text_as(bytes, &python).unwrap(), text, "{python}");
}
assert_eq!(decode_text_as(&cases[1].1, "utf-16").unwrap(), text);
assert_eq!(decode_text_as(&cases[3].1, "utf-32").unwrap(), text);
assert_eq!(decode_text(&utf8_bom).unwrap(), text);
assert_eq!(
decode_text_as(text.as_bytes(), "utf-8").unwrap(),
decode_text(text.as_bytes()).unwrap()
);
assert_eq!(
decode_text_as(&utf8_bom, "cp1252").unwrap(),
"# Title\nHello"
);
assert!(decode_text_as(b"x", "not-a-codec").is_err());
assert!(decode_text_as(b"\xff\xfeA", "utf-16-le").is_err());
}
#[test]
fn damaged_input_behind_a_mark_names_its_encoding() {
for (raw, codec) in [
(&b"\xef\xbb\xbf\xff"[..], "utf-8-sig"),
(b"\xef\xbb\xbfcaf\xe9 na\xefve", "utf-8-sig"),
(b"\xff\xfeA", "utf-16"),
(b"\xfe\xff\x00", "utf-16"),
(b"\xff\xfe\x00\x00A\x00\x00", "utf-32"),
(b"\x00\x00\xfe\xff\x00\x00\x00", "utf-32"),
] {
let err = decode_text(raw).unwrap_err().to_string();
assert!(err.contains(&format!("'{codec}'")), "{raw:?}: {err}");
}
}
#[test]
fn text_documents_decode_like_docling() {
assert_eq!(decode_text("caf\u{e9}".as_bytes()).unwrap(), "caf\u{e9}");
assert!(matches!(
decode_text(b"plain").unwrap(),
std::borrow::Cow::Borrowed(_)
));
assert_eq!(decode_text(b"\xef\xbb\xbf# T").unwrap(), "# T");
assert_eq!(decode_text(b"\xff\xfeh\x00i\x00").unwrap(), "hi");
assert_eq!(decode_text(b"\xfe\xff\x00h\x00i").unwrap(), "hi");
assert_eq!(decode_text(b"\xff\xfe\x00\x00h\x00\x00\x00").unwrap(), "h");
assert_eq!(
decode_text(b"caf\xe9 \x93q\x94").unwrap(),
"caf\u{e9} \u{201c}q\u{201d}"
);
let damaged = decode_text(b"caf\xc3\xa9 na\xc3\xafve \xff");
assert!(damaged.unwrap_err().to_string().contains("damaged UTF-8"));
assert!(decode_text(b"x\x81y").is_err());
let sjis = "名前,年齢,住所\n佐藤太郎,30,東京\n髙橋淳,35,名古屋\n";
let (bytes, _, _) = encoding_rs::SHIFT_JIS.encode(sjis);
assert_eq!(decode_text(&bytes).unwrap(), sjis);
let koi = "Отчёт о командировке: встречи с заказчиком, обсуждение сроков.";
let (bytes, _, _) = encoding_rs::KOI8_R.encode(koi);
assert_eq!(decode_text(&bytes).unwrap(), koi);
let gbk = "本周完成了数据导入模块的开发,并与测试团队一起验证了常见的输入格式。";
let (bytes, _, _) = encoding_rs::GBK.encode(gbk);
assert_eq!(decode_text(&bytes).unwrap(), gbk);
let (bytes, _, _) =
encoding_rs::WINDOWS_1250.encode("Zażółć gęślą jaźń, zażółć gęślą jaźń.");
let (want, _) = encoding_rs::WINDOWS_1252.decode_without_bom_handling(&bytes);
assert_eq!(decode_text(&bytes).unwrap(), want);
assert_eq!(
decode_text_as(&bytes, "windows-1250").unwrap(),
"Zażółć gęślą jaźń, zażółć gęślą jaźń."
);
}
}
pub(crate) fn refine_format(format: InputFormat, bytes: &[u8]) -> InputFormat {
if format == InputFormat::Html && crate::backend::is_ixbrl(bytes) {
InputFormat::XmlXbrl
} else {
format
}
}
fn local_source_path(uri: &str) -> Result<PathBuf, String> {
let Some(rest) = uri
.get(..5)
.filter(|scheme| scheme.eq_ignore_ascii_case("file:"))
.map(|_| &uri[5..])
else {
return if uri.is_empty() {
Err("empty path".into())
} else {
Ok(PathBuf::from(uri))
};
};
let (authority, path) = match rest.strip_prefix("//") {
Some(after) => match after.find('/') {
Some(i) => (&after[..i], &after[i..]),
None => (after, ""),
},
None => ("", rest),
};
let path = String::from_utf8(crate::fetch::percent_decode(path))
.map_err(|_| "the path is not UTF-8".to_string())?;
if path.is_empty() {
return Err("empty path".into());
}
if path.trim_end_matches('/').is_empty() {
return Err("the URI names the root directory, not a file".into());
}
let local = authority.is_empty() || authority.eq_ignore_ascii_case("localhost");
if !local {
return if cfg!(windows) {
Ok(PathBuf::from(format!(
r"\\{authority}{}",
path.replace('/', "\\")
)))
} else {
Err("a file URI with a host other than localhost needs a Windows UNC path".into())
};
}
if cfg!(windows) {
let b = path.as_bytes();
if b.len() >= 3 && b[0] == b'/' && b[1].is_ascii_alphabetic() && b[2] == b':' {
return Ok(PathBuf::from(&path[1..]));
}
}
Ok(PathBuf::from(path))
}
#[cfg(test)]
mod source_uri_tests {
use super::*;
#[test]
fn local_source_paths() {
let p = |u: &str| local_source_path(u).map(|p| p.to_string_lossy().into_owned());
assert_eq!(p("/data/a.nxml").unwrap(), "/data/a.nxml");
if !cfg!(windows) {
assert_eq!(p("file:///data/a.nxml").unwrap(), "/data/a.nxml");
assert_eq!(p("file://LoCaLhOsT/data/a.nxml").unwrap(), "/data/a.nxml");
assert_eq!(
p("file:///data/space%20%E4%B8%AD%E6%96%87/a.nxml").unwrap(),
"/data/space 中文/a.nxml"
);
assert!(p("file://server/share/a.nxml").is_err());
}
assert!(p("file:///").is_err());
assert!(p("file://").is_err());
assert!(p("").is_err());
}
#[test]
fn source_uri_sets_the_path_or_the_base_url() {
let src = || SourceDocument::from_bytes("a.nxml", InputFormat::XmlJats, Vec::new());
let file = src().with_source_uri("file:///tmp/x/a.nxml");
assert_eq!(file.path.as_deref(), Some(Path::new("/tmp/x/a.nxml")));
let web = src().with_source_uri("https://example.org/a.html");
assert_eq!(web.base_url.as_deref(), Some("https://example.org/a.html"));
assert!(web.path.is_none());
assert!(src().with_source_uri("file:///").path.is_none());
}
}