Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@salesforcedevs/sfdocs-image-transformer

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salesforcedevs/sfdocs-image-transformer - npm Package Compare versions

Comparing version 1.0.5-fix-alpha to 1.0.5-fix-alpha1

4

dist/image-cdn-mapper.d.ts

@@ -8,6 +8,2 @@ import { VFile } from 'vfile';

};
/** Function to check if the provided imagePath is a local path or not
* If the URL start with https:// or www. or /, then this function returns
* false (meaning, these path are treated as external URL's)
*/
export declare function isInternalPath(imagePath: string): boolean;

@@ -14,0 +10,0 @@ /**

7

dist/image-cdn-mapper.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateImagePath = exports.isInternalPath = void 0;
/** Function to check if the provided imagePath is a local path or not
* If the URL start with https:// or www. or /, then this function returns
* false (meaning, these path are treated as external URL's)
*/
// Function to check if the provided imagePath is a local path or not
function isInternalPath(imagePath) {
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.|\/).*/));
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.).*/));
}

@@ -11,0 +8,0 @@ exports.isInternalPath = isInternalPath;

@@ -15,2 +15,11 @@ "use strict";

/**
* Function to check if the image path is already transformed,
* if path is transformed we will not transform them again.
* @param imagePath
* @returns true/false
*/
function isTransformedPath(imagePath) {
return imagePath && path_1.default.isAbsolute(imagePath) && !imagePath.startsWith('/media');
}
/**
* Function to transform the internal image paths to include ./ as a prefix.

@@ -25,3 +34,3 @@ * If an image path is '../media/maps.png', then it will be transformed to './../media/maps.png'

const imagePath = node.url;
if ((0, image_cdn_mapper_1.isInternalPath)(imagePath) && !imagePath.startsWith('./')) {
if ((0, image_cdn_mapper_1.isInternalPath)(imagePath) && !imagePath.startsWith('./') && !isTransformedPath(imagePath)) {
const prefix = path_1.default.isAbsolute(imagePath) ? '.' : './';

@@ -28,0 +37,0 @@ node.url = prefix + imagePath;

{
"version": "1.0.5-fix-alpha",
"version": "1.0.5-fix-alpha1",
"name": "@salesforcedevs/sfdocs-image-transformer",

@@ -4,0 +4,0 @@ "description": "Salesforce Docs markdown plugin for image transormation",

@@ -166,4 +166,14 @@ import vfile, { VFile } from 'vfile';

})
});
test('absolute paths should not be prefixed with "./" if not path is already transformed', () => {
const markdown = '![SalesforceDocs](/user/test/media/salesforcedocs.png)';
const result = processMarkdown(markdown);
const contents = result.contents;
expect(contents).toEqual(
'<p><img src="/user/test/media/salesforcedocs.png" alt="SalesforceDocs"></p>',
);
});
});

@@ -11,8 +11,5 @@ import { VFile } from 'vfile';

/** Function to check if the provided imagePath is a local path or not
* If the URL start with https:// or www. or /, then this function returns
* false (meaning, these path are treated as external URL's)
*/
// Function to check if the provided imagePath is a local path or not
export function isInternalPath(imagePath: string): boolean {
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.|\/).*/));
return imagePath && !(imagePath.match(/^(https?:\/\/|www\.).*/));
}

@@ -19,0 +16,0 @@

@@ -19,2 +19,12 @@ import { Transformer } from 'unified';

/**
* Function to check if the image path is already transformed,
* if path is transformed we will not transform them again.
* @param imagePath
* @returns true/false
*/
function isTransformedPath(imagePath: string): boolean {
return imagePath && path.isAbsolute(imagePath) && !imagePath.startsWith('/media');
}
/**
* Function to transform the internal image paths to include ./ as a prefix.

@@ -29,3 +39,3 @@ * If an image path is '../media/maps.png', then it will be transformed to './../media/maps.png'

const imagePath = node.url;
if (isInternalPath(imagePath) && !imagePath.startsWith('./')) {
if (isInternalPath(imagePath) && !imagePath.startsWith('./') && !isTransformedPath(imagePath)) {
const prefix = path.isAbsolute(imagePath) ? '.' : './';

@@ -32,0 +42,0 @@ node.url = prefix + imagePath;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc