Skip to content

Commit

Permalink
sanitize filename and forbid certain characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kriechi committed Jan 4, 2020
1 parent 7d1affe commit 84ff2e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog of Cura-DuetRRFPlugin

## v1.0.5: 2019-11-10
* sanitize filename and forbid certain characters

## v1.0.4: 2019-11-10
* bump compatibility for Cura 4.4 / API 7.0

Expand Down
18 changes: 16 additions & 2 deletions DuetRRFOutputDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,25 @@ def requestWrite(self, node, fileName=None, *args, **kwargs):
self._dialog.findChild(QObject, "nameField").setProperty('focus', True)

def onFilenameChanged(self):
fileName = self._dialog.findChild(QObject, "nameField").property('text')
fileName = self._dialog.findChild(QObject, "nameField").property('text').strip()

forbidden_characters = "\"'´`<>()[]?*\,;:&%#$!"

This comment has been minimized.

Copy link
@ninovanhooff

ninovanhooff Jan 21, 2020

Hi there, Ultimaker plugin reviewer here.

I recommend to use a regex for this. No reason to reject the plugin, but you might want to change this for the next release

for forbidden_character in forbidden_characters:
if forbidden_character in fileName:
self._dialog.setProperty('validName', False)
self._dialog.setProperty('validationError', 'Filename cannot contain {}'.format(forbidden_characters))
return

if fileName == '.' or fileName == '..':
self._dialog.setProperty('validName', False)
self._dialog.setProperty('validationError', 'Filename cannot be "." or ".."')
return

self._dialog.setProperty('validName', len(fileName) > 0)
self._dialog.setProperty('validationError', 'Filename too short')

def onFilenameAccepted(self):
self._fileName = self._dialog.findChild(QObject, "nameField").property('text')
self._fileName = self._dialog.findChild(QObject, "nameField").property('text').strip()
if not self._fileName.endswith('.gcode') and '.' not in self._fileName:
self._fileName += '.gcode'
Logger.log("d", self._name_id + " | Filename set to: " + self._fileName)
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"name": "DuetRRF",
"author": "Thomas Kriechbaumer",
"description": "Upload and Print to DuetWifi / DuetEthernet / Duet Maestro with RepRapFirmware.",
"version": "1.0.4",
"version": "1.0.5",
"api": "7.0.0"
}
4 changes: 2 additions & 2 deletions resources/qml/UploadFilename.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ UM.Dialog
text: base.object;
maximumLength: 100;
onTextChanged: base.textChanged(text);
Keys.onReturnPressed: base.accept();
Keys.onEnterPressed: base.accept();
Keys.onReturnPressed: { if (base.validName) base.accept(); }
Keys.onEnterPressed: { if (base.validName) base.accept(); }
Keys.onEscapePressed: base.reject();
}

Expand Down

0 comments on commit 84ff2e1

Please sign in to comment.