forked from capricorn86/happy-dom
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
capricorn86#204@trivial: Improves performance and fixes some minor bu…
…gs related to blob urls.
- Loading branch information
1 parent
69b2150
commit c54734d
Showing
6 changed files
with
187 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/happy-dom/src/nodes/html-anchor-element/HTMLAnchorElementUtility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import IDocument from '../document/IDocument'; | ||
import { URL } from 'url'; | ||
|
||
/** | ||
* HTML Anchor Element utility. | ||
*/ | ||
export default class HTMLAnchorElementUtility { | ||
/** | ||
* Returns "true" if it is a blob URL. | ||
* | ||
* According to spec, if element's url is non-null, its scheme is "blob", and it has an opaque path, then the process of updating properties on the URL should be terminated. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/links.html#reinitialise-url | ||
* @param url | ||
* @param url URL. | ||
* @returns "true" if blob URL. | ||
*/ | ||
public static isBlobURL(url: URL): boolean { | ||
return ( | ||
url && url.protocol === 'blob:' && url.pathname.length > 1 && url.pathname.includes('://') | ||
); | ||
} | ||
|
||
/** | ||
* Returns URL. | ||
* | ||
* @see https://html.spec.whatwg.org/multipage/links.html#dom-hyperlink-href | ||
* @see https://html.spec.whatwg.org/multipage/links.html#hyperlink | ||
* @param document Document. | ||
* @param href Href. | ||
* @returns URL. | ||
*/ | ||
public static getUrl(document: IDocument, href: string | null): URL { | ||
if (!href) { | ||
return null; | ||
} | ||
|
||
const documentUrl = document.location.href; | ||
|
||
try { | ||
return new URL(href.trim(), documentUrl); | ||
} catch (TypeError) { | ||
// Ignore error | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.