Skip to content

Commit 2a6d798

Browse files
authored
Merge pull request #4195 from kchadha/fix-filename-regex
Fix regex for extracting the project title from a .sb file
2 parents 135e521 + 41d9100 commit 2a6d798

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/containers/sb-file-uploader.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,9 @@ class SBFileUploader extends React.Component {
8080
}
8181
getProjectTitleFromFilename (fileInputFilename) {
8282
if (!fileInputFilename) return '';
83-
// only parse title from files like "filename.sb2" or "filename.sb3"
84-
const matches = fileInputFilename.match(/^(.*)\.sb[23]$/);
83+
// only parse title with valid scratch project extensions
84+
// (.sb, .sb2, and .sb3)
85+
const matches = fileInputFilename.match(/^(.*)\.sb[23]?$/);
8586
if (!matches) return '';
8687
return matches[1].substring(0, 100); // truncate project title to max 100 chars
8788
}

test/unit/containers/sb-file-uploader.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ describe('SBFileUploader Container', () => {
6565
expect(projectName).toBe('my project is great');
6666
});
6767

68-
test('sets blank title with .sb filename', () => {
68+
test('correctly sets title with .sb filename', () => {
6969
const wrapper = shallowWithIntl(getContainer(), {context: {store}});
7070
const instance = wrapper
7171
.dive() // unwrap redux Connect(InjectIntl(SBFileUploader))
7272
.dive() // unwrap InjectIntl(SBFileUploader)
7373
.instance(); // SBFileUploader
7474
const projectName = instance.getProjectTitleFromFilename('my project is great.sb');
75-
expect(projectName).toBe('');
75+
expect(projectName).toBe('my project is great');
7676
});
7777

7878
test('sets blank title with filename with no extension', () => {

0 commit comments

Comments
 (0)