From 10bdf647bc22007738d5345d6dc08f108290628e Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 1 Nov 2020 21:27:40 +0800 Subject: [PATCH] Fix fetch resources url incorrect --- CHANGELOG.md | 5 +++++ package.json | 2 +- src/uri.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 193caaf..5177059 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.2] - 2020-11-01 + +### Fixed +- Fix fetch resources url incorrect + ## [2.1.1] - 2020-10-30 ### Fixed diff --git a/package.json b/package.json index 7473abc..ee3bf8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@wabarc/cairn", - "version": "2.1.1", + "version": "2.1.2", "description": "Node package and CLI tool for saving web page as single HTML file", "main": "dist/cairn.js", "types": "dist/cairn.d.ts", diff --git a/src/uri.ts b/src/uri.ts index a5ef8bf..2a682d8 100644 --- a/src/uri.ts +++ b/src/uri.ts @@ -1,4 +1,4 @@ -import { createAbsoluteURL, http } from './utils'; +import { createAbsoluteURL, isValidURL, http } from './utils'; import { css } from './css'; class URI { @@ -9,6 +9,10 @@ class URI { } const assetURL = createAbsoluteURL(url, baseURL); + if (!isValidURL(assetURL)) { + return content; + } + const response = await http.fetch(assetURL); if (typeof response !== 'object' || !Object.prototype.hasOwnProperty.call(response, 'data')) { return content; @@ -17,7 +21,7 @@ class URI { const contentType = response.headers['content-type'] || ''; if (contentType === 'text/css') { - content = await css.process(Buffer.from(content).toString(), baseURL); + content = await css.process(Buffer.from(content).toString(), assetURL); } return content;