Skip to content

Improper loading of static files on 404 pages #2256

Open
@lindapaiste

Description

@lindapaiste

p5.js version

No response

What is your operating system?

None

Web browser and version

No response

Actual Behavior

image

This one is not easily reproducible because the 404 pages choose a sketch at random, so I can't link to a particular URL where it happens. However I noticed it on a 404 page which attempted to render this sketch: https://editor.p5js.org/p5/sketches/Advanced_Data:_Load_Saved_Table

This sketch loads a .csv file:

function preload() {
  table = loadTable("assets/bubbles.csv", "header");
}

The /server/views/404Page.js file re-writes that path:

// Fix links to assets
htmlFile = htmlFile.replace(
/'assets/g,
"'https://rawgit.com/processing/p5.js-website/main/dist/assets/examples/assets/"
);
htmlFile = htmlFile.replace(
/"assets/g,
'"https://rawgit.com/processing/p5.js-website/main/dist/assets/examples/assets/'
);

And we get a URL https://rawgit.com/processing/p5.js-website/main/dist/assets/examples/assets//bubbles.csv which does not exist. The rawgit.com service has actually been deprecated since 2018 and it should not be used. But it does still work if we use the correct URL, which is https://rawgit.com/processing/p5.js-website/main/src/data/examples/assets/bubbles.csv as the file is located at https://github.com/processing/p5.js-website/blob/main/src/data/examples/assets/bubbles.csv. The fatal problem is that we are creating improper paths.

Expected Behavior

When the sketch is run by the previewServer, the output code is:

function preload() {
  table = loadTable("https://cdn.jsdelivr.net/gh/processing/p5.js-website@main/src/data/examples/assets/bubbles.csv", "header");
}

This works, and it matches what is included in the .files property of the sketch object:

{
    "name": "bubbles.csv",
    "content": "",
    "children": [],
    "fileType": "file",
    "_id": "6459341065978bfc7dc6c7b4",
    "url": "https://cdn.jsdelivr.net/gh/processing/p5.js-website@main/src/data/examples/assets/bubbles.csv",
    "createdAt": "2023-05-08T17:40:32.645Z",
    "updatedAt": "2023-05-08T17:40:32.645Z",
    "id": "6459341065978bfc7dc6c7b4"
}

Steps to reproduce

It happens at random on any 404 URL, depending on which sketch is chosen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions