Skip to content

Filenames of imported files are truncated improperly when containing multiple periods #406

@CubeSolver25

Description

@CubeSolver25

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:

  1. Open the Scratch Editor (either via the Offline Editor or web browser)
  2. Click Upload Sprite, Upload Backdrop, Upload Costume, or Upload Sound.
  3. 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
Image
Expected Behavior: Uploaded as costume named MAX.(period)
Image
Actual Behavior: Uploaded as costume named MAX
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions