Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ajax request error for urls created by createObjectURL #3739

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Sanshain
Copy link

@Sanshain Sanshain commented Jul 13, 2022

What: enable possibility using urls created by URL.createObjectURL to less compilation

        let c = `h2 { color : green; cursor: pointer; }`
        let b = new Blob([c], {
            type: 'text/css'
        })
        let url =  URL.createObjectURL(b);
        
        const link = document.createElement('link')
        
        link.href = url;
        link.type = "text/x-less"
        link.rel = "stylesheet/less";

        document.body.appendChild(link)

Why: without changes we have following error:

image

Sample code here https://codepen.io/Alsoo/pen/GRxjGZa (not reproduced on codepen)

How: links created using createObjectURL always start with blob: and are automatically added to the base part of the host name. Therefore, the simplest and most effective way to identify such links is to check whether they start with the blob part, bypassing the extractUrlParts function:

const href      = filename.startsWith('blob:') ? filename : hrefParts.url;

instead of

const href      = hrefParts.url;

This solution does not break any test and total solves all problems with blob links (checked)

  • Documentation
  • Added/updated unit tests
  • Code complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant