PrismJS / PrismJS/prism

JSONP Highlight plugin doesn't handle 301 redirects

Open
#3,012 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement plugins
Dominant language
JavaScript
Stars
13k
Forks
1.4k
Avg merge
15h 36m
Merged PRs (30d)
3

Description

Information:

  • Prism version: 1.24.1
  • Plugins: jsonp-highlight
  • Environment: Browser

Description

The example below is the minimal example from the docs:

<pre
	class="language-javascript"
	data-jsonp="https://api.github.com/repos/leaverou/prism/contents/prism.js">
</pre>

... which for me resulted in the following being rendered:

✖ Error: Cannot parse response (perhaps you need an adapter function?)

Debugging the error with the dev tools reveals that the problem is the 301 response:

image

As soon as I change data-jsonp to the redirect location https://api.github.com/repositories/4979467/contents/prism.js?callback=prismjsonp0, everything works as expected.

Solution

  • Handle 301 status codes
  • Temporarily update the minimal example in the docs with an URL that returns a status code 400, so people don't get confused

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the jsonp-highlight plugin entry point and the minimal JSONP example in the documentation. Reproduce the request using the documented GitHub URL and inspect how the 301 response is handled. Done means redirected responses work and the documentation example no longer points to a confusing URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.