From 12128e1760711ba0091e458152f3a5ac8c968e1d Mon Sep 17 00:00:00 2001
From: Felix <188768+fb55@users.noreply.github.com>
Date: Sun, 1 May 2022 10:32:57 +0100
Subject: [PATCH] feat(attributes): Add `baseURI` option (#2510)
---
src/api/attributes.spec.ts | 39 ++++++++++++++++++++++++++++++++++++++
src/api/attributes.ts | 39 ++++++++++++++++++++++++++++++++++++++
src/options.ts | 10 ++++++++--
3 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/src/api/attributes.spec.ts b/src/api/attributes.spec.ts
index 340e78c6fe..b7a3b8a476 100644
--- a/src/api/attributes.spec.ts
+++ b/src/api/attributes.spec.ts
@@ -243,6 +243,7 @@ describe('$(...)', () => {
expect(imgs.prop('namespace')).toBe(nsHtml);
imgs.prop('attribs', null);
expect(imgs.prop('src')).toBeUndefined();
+ expect(imgs.prop('data-foo')).toBeUndefined();
});
it('(map) : object map should set multiple props', () => {
@@ -284,6 +285,44 @@ describe('$(...)', () => {
expect($(null as any).prop('prop')).toBeUndefined();
});
+ it('("href") : should resolve links with `baseURI`', () => {
+ const $ = cheerio.load(
+ `
+ example1
+ example2
+ example3
+ example4
+ `,
+ { baseURI: 'http://example.com/page/1' }
+ );
+
+ expect($('#1').prop('href')).toBe('http://example.org/');
+ expect($('#2').prop('href')).toBe('http://example.org/');
+ expect($('#3').prop('href')).toBe('http://example.com/example.org');
+ expect($('#4').prop('href')).toBe('http://example.com/page/example.org');
+ });
+
+ it('("src") : should resolve links with `baseURI`', () => {
+ const $ = cheerio.load(
+ `
+
+
+
+