New:Socket for Asana Is Now Available.Learn more
Get Started

postcss-normalize-url

Package Overview
Dependencies
Maintainers
8
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-normalize-url - npm Package Compare versions

Comparing version
8.0.3
to
8.0.4
+2
-2
package.json
{
"name": "postcss-normalize-url",
"version": "8.0.3",
"version": "8.0.4",
"description": "Normalize URLs with PostCSS",

@@ -49,3 +49,3 @@ "exports": {

"type": "git",
"url": "cssnano/cssnano"
"url": "git+https://github.com/cssnano/cssnano.git"
},

@@ -52,0 +52,0 @@ "bugs": {

@@ -6,2 +6,8 @@ 'use strict';

/**
* A `quote` assignment target for value-parser nodes that aren't otherwise
* typed: retags the node as a (possibly unquoted) string node.
* @typedef {{ quote?: string }} QuotedNode
*/
const multiline = /\\[\r\n]/;

@@ -65,3 +71,3 @@ // eslint-disable-next-line no-useless-escape

/** @type {valueParser.Node} */ (node).type = 'string';
/** @type {any} */ (node).quote =
/** @type {QuotedNode} */ (node).quote =
node.nodes[0].type === 'string' ? node.nodes[0].quote : '"';

@@ -102,3 +108,3 @@ node.value = node.nodes[0].value;

if (url.value.length === 0) {
/** @type {any} */ (url).quote = '';
/** @type {QuotedNode} */ (url).quote = '';

@@ -105,0 +111,0 @@ return false;

@@ -97,23 +97,23 @@ 'use strict';

function normalizeUrl(urlString) {
urlString = urlString.trim();
const trimmedUrl = urlString.trim();
// Data URL
if (urlRegex.test(urlString)) {
return normalizeDataURL(urlString);
if (urlRegex.test(trimmedUrl)) {
return normalizeDataURL(trimmedUrl);
}
if (hasCustomProtocol(urlString)) {
return urlString;
if (hasCustomProtocol(trimmedUrl)) {
return trimmedUrl;
}
const hasRelativeProtocol = urlString.startsWith('//');
const hasRelativeProtocol = trimmedUrl.startsWith('//');
const isRelativeUrl =
!hasRelativeProtocol && relativePathRegex.test(urlString);
!hasRelativeProtocol && relativePathRegex.test(trimmedUrl);
// Prepend protocol
if (!isRelativeUrl) {
urlString = urlString.replace(protocolRegex, 'http:');
}
const withProtocol = isRelativeUrl
? trimmedUrl
: trimmedUrl.replace(protocolRegex, 'http:');
const urlObject = new URL(urlString);
const urlObject = new URL(withProtocol);

@@ -143,7 +143,7 @@ // Remove duplicate slashes if not preceded by a protocol

// Take advantage of many of the Node `url` normalizations
urlString = urlObject.toString();
let result = urlObject.toString();
// Remove ending `/`
if (urlObject.pathname === '/' && urlObject.hash === '') {
urlString = urlString.replace(trailingSlashRegex, '');
result = result.replace(trailingSlashRegex, '');
}

@@ -153,8 +153,8 @@

if (hasRelativeProtocol) {
urlString = urlString.replace(httpProtocolRegex, '//');
result = result.replace(httpProtocolRegex, '//');
}
return urlString;
return result;
}
module.exports = normalizeUrl;
declare const _exports: import("postcss").PluginCreator<void>;
export = _exports;
export type QuotedNode = {
quote?: string;
};
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;AAQG,YAA8B,UAAU,GAA9B;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAY"}