Skip to content

Commit

Permalink
Fix: wrong load external resources when the local protocol is file:// (
Browse files Browse the repository at this point in the history
…#309)

When an external image resource is loaded from https, the function
convertUrlToAbsolute inside the utils.ts doesn't check if it is a
network or internal resource.
  • Loading branch information
frank-weindel authored Jun 26, 2024
2 parents e347626 + eba04ee commit 632ffd9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* limitations under the License.
*/

export const PROTOCOL_REGEX = /^(data|ftps?|https?):/;

export type RGBA = [r: number, g: number, b: number, a: number];
export const getNormalizedRgbaComponents = (rgba: number): RGBA => {
const r = rgba >>> 24;
Expand Down Expand Up @@ -250,8 +252,8 @@ export function isRectPositive(rect: Rect): boolean {
}

export function convertUrlToAbsolute(url: string): string {
// handle local file imports
if (self.location.protocol === 'file:') {
// handle local file imports if the url isn't remote resource or data blob
if (self.location.protocol === 'file:' && !PROTOCOL_REGEX.test(url)) {
const path = self.location.pathname.split('/');
path.pop();
const basePath = path.join('/');
Expand Down

0 comments on commit 632ffd9

Please sign in to comment.