scratchfoundation / scratchfoundation/scratch-editor
Filenames of imported files are truncated improperly when containing multiple periods
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 281
- Forks
- 276
- Avg merge
- 7d 8h
- Merged PRs (30d)
- 6
Description
Expected Behavior
When a file is uploaded to Scratch (whether as a sprite, costume, backdrop, sound, etc.), only the file extension should be removed from the filename, if it exists.
Because a file's extension is determined by the contents of the filename after the last period, if a filename has multiple periods, only the last period (and the characters that follow) should be removed when uploaded.
e.g. An image with the filename image.jpg.png is treated as a PNG, and thus should be imported with the asset name image.jpg if the intention is to remove only the file extension when importing files to Scratch.
Actual Behavior
If a file with more than one period in its name is imported, the filename is truncated to the first period, not the last.
This leads to the filename being truncated before the actual file extension.
Based on the code responsible for this behavior and its comments, this code appears to be working as intended, but I am still reporting this as an issue on the basis of that intended behavior being undesirable from my perspective.
From file-uploader.js:
const extractFileName = function (nameExt) {
// There could be multiple dots, but get the stuff before the first .
const nameParts = nameExt.split('.', 1); // we only care about the first .
return nameParts[0];
};
Steps to Reproduce
Steps to reproduce the behavior:
- Open the Scratch Editor (either via the Offline Editor or web browser)
- Click
Upload Sprite,Upload Backdrop,Upload Costume, orUpload Sound. - Select and upload a compatible file with more than one period in its filename.
System Details
Browser: Google Chrome 143.0.7499.170 (arm64)
Offline Editor: Version 3.31.1 (Downloaded from Mac App Store)
Operating System: macOS Tahoe 26.2
Screenshots
Original Filename: MAX.(period).png
Expected Behavior: Uploaded as costume named MAX.(period)
Actual Behavior: Uploaded as costume named MAX
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/lib/file-uploader.js at extractFileName and reproduce the upload with a filename containing multiple periods. Verify that the imported asset name removes only the final extension, such as importing image.jpg.png as image.jpg, and check the affected upload flows for sprites, costumes, backdrops, and sounds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100