Skip to content

Block Python file writes without an extension - #1675

Merged
jamiebenstead merged 2 commits into
mainfrom
1555-prevent-blank-extension-components-being-created
Oct 5, 2026
Merged

jamiebenstead merged 2 commits into
mainfrom
1555-prevent-blank-extension-components-being-created

Conversation

@jamiebenstead

Copy link
Copy Markdown
Contributor

closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1555

This fixes users creating blank extensions by using code like -

f = open("test", "w")
f.write("testing")

Previously we added validation to the new file/rename modals, but this is a way to create files without an extension still.

Comment thread src/PyodideWorker.js

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Filename parsing still permits blank component extensions, and the new test does not execute the validation.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds extension validation to Python file writes, complementing the editor’s existing new-file and rename checks.

Changes:

  • Rejects extensionless text-file writes with an OSError.
  • Adds a worker test checking that the validation message is included.
File Description
src/​PyodideWorker.js Adds extension validation for text-file writes.
src/​components/​Editor/​Runners/​PythonRunner/​PyodideRunner/​PyodideWorker.test.js Checks for the validation message in injected Python source.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/PyodideWorker.js
- Block names with an empty part between dots (e.g. "test..txt"),
  which the New File modal already rejects
- Split file names in handleFileWrite like NewFileModal does
  (extension = everything after the first dot), so a write can't
  create a component with a blank extension
- Add Cypress tests for extensionless writes in w/a/x modes and for
  names with consecutive dots

@zetter-rpf zetter-rpf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one on finding the cause for this, and I agree this change should reduce the errors.

What I'm unsure about is if we should require files to have an extension. I can see some value in this restriction when creating files in the editor so that a person doesn't accidentally create a non *.py file that won't run/import, but if the file is being created programatically I'm not sure what the purpose of this restriction is. The volume of errors makes me wonder if there might be project that gets people to write files that might be working.

What do you think?

@jamiebenstead

Copy link
Copy Markdown
Contributor Author

What I'm unsure about is if we should require files to have an extension.

@zetter-rpf I did try without this, and what I found is that it would create files with a type of undefined. So for example test.undefined which looked messy to me. What do you think?

@zetter-rpf

Copy link
Copy Markdown
Contributor

@zetter-rpf I did try without this, and what I found is that it would create files with a type of undefined. So for example test.undefined which looked messy to me. What do you think?

I think we would need to change that behaviour too if we wanted to allow files without extensions

@jamiebenstead
jamiebenstead merged commit 8f75bf0 into main Oct 5, 2026
12 checks passed
@jamiebenstead
jamiebenstead deleted the 1555-prevent-blank-extension-components-being-created branch October 5, 2026 15:24

This branch was successfully deployed

1 active deployment
previews/1675/merge — 5e956894 Deployed Oct 5, 2026 by jamiebenstead via deploy-branch / build-deploy #6853
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.

3 participants