Skip to content

Commit 87a5306

Browse files
committed
- use newest test
- remove useless binding - regroup function
1 parent f4259bb commit 87a5306

File tree

3 files changed

+39
-50
lines changed

3 files changed

+39
-50
lines changed

Diff for: browser/main/Detail/MarkdownNoteDetail.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ class MarkdownNoteDetail extends React.Component {
460460
storageKey={note.storage}
461461
noteKey={note.key}
462462
linesHighlighted={note.linesHighlighted}
463-
onChange={this.handleUpdateContent.bind(this)}
463+
onChange={this.handleUpdateContent}
464464
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
465465
getNote={this.getNote}
466466
RTL={config.editor.rtlEnabled && this.state.RTL}
@@ -475,7 +475,7 @@ class MarkdownNoteDetail extends React.Component {
475475
storageKey={note.storage}
476476
noteKey={note.key}
477477
linesHighlighted={note.linesHighlighted}
478-
onChange={this.handleUpdateContent.bind(this)}
478+
onChange={this.handleUpdateContent}
479479
ignorePreviewPointerEvents={ignorePreviewPointerEvents}
480480
getNote={this.getNote}
481481
RTL={config.editor.rtlEnabled && this.state.RTL}

Diff for: browser/main/lib/dataApi/attachmentManagement.js

+6-27
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,15 @@ function replaceNoteKeyWithNewNoteKey(noteContent, oldNoteKey, newNoteKey) {
706706
}
707707

708708
/**
709-
* @description Deletes all :storage and noteKey references from the given input.
710-
* @param input Input in which the references should be deleted
709+
* @description replace all :storage references with given destination folder.
710+
* @param input Input in which the references should be replaced
711711
* @param noteKey Key of the current note
712+
* @param destinationFolder Destination folder of the attachements
712713
* @returns {String} Input without the references
713714
*/
714-
function removeStorageAndNoteReferences(input, noteKey) {
715+
function replaceStorageReferences(input, noteKey, destinationFolder) {
715716
return input.replace(
716-
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '.*?("|\\))', 'g'),
717+
new RegExp('/?' + STORAGE_FOLDER_PLACEHOLDER + '[^"\\)<\\s]+', 'g'),
717718
function(match) {
718719
return match
719720
.replace(new RegExp(mdurl.encode(path.win32.sep), 'g'), path.posix.sep)
@@ -735,33 +736,12 @@ function removeStorageAndNoteReferences(input, noteKey) {
735736
')?',
736737
'g'
737738
),
738-
DESTINATION_FOLDER
739+
destinationFolder
739740
)
740741
}
741742
)
742743
}
743744

744-
/**
745-
* @description replace all :storage references with given destination folder.
746-
* @param input Input in which the references should be replaced
747-
* @param noteKey Key of the current note
748-
* @param destinationFolder Destination folder of the attachements
749-
* @returns {String} Input without the references
750-
*/
751-
function replaceStorageReferences(input, noteKey, destinationFolder) {
752-
return input.replace(
753-
new RegExp(
754-
STORAGE_FOLDER_PLACEHOLDER +
755-
'(' +
756-
escapeStringRegexp(path.sep) +
757-
noteKey +
758-
')?',
759-
'g'
760-
),
761-
destinationFolder || DESTINATION_FOLDER
762-
)
763-
}
764-
765745
/**
766746
* @description Deletes the attachment folder specified by the given storageKey and noteKey
767747
* @param storageKey Key of the storage of the note to be deleted
@@ -1122,7 +1102,6 @@ module.exports = {
11221102
getAttachmentsInMarkdownContent,
11231103
getAbsolutePathsOfAttachmentsInContent,
11241104
importAttachments,
1125-
removeStorageAndNoteReferences,
11261105
removeAttachmentsByPaths,
11271106
replaceStorageReferences,
11281107
deleteAttachmentFolder,

Diff for: tests/dataApi/attachmentManagement.test.js

+31-21
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,15 @@ it('should remove the all ":storage" and noteKey references', function() {
702702
' </p>\n' +
703703
' </body>\n' +
704704
'</html>'
705-
const actual = systemUnderTest.removeStorageAndNoteReferences(
705+
const actual = systemUnderTest.replaceStorageReferences(
706706
testInput,
707-
noteKey
707+
noteKey,
708+
systemUnderTest.DESTINATION_FOLDER
708709
)
709710
expect(actual).toEqual(expectedOutput)
710711
})
711712

712-
it('should make sure that "removeStorageAndNoteReferences" works with markdown content as well', function() {
713+
it('should make sure that "replaceStorageReferences" works with markdown content as well', function() {
713714
const noteKey = 'noteKey'
714715
const testInput =
715716
'Test input' +
@@ -736,9 +737,10 @@ it('should make sure that "removeStorageAndNoteReferences" works with markdown c
736737
systemUnderTest.DESTINATION_FOLDER +
737738
path.posix.sep +
738739
'pdf.pdf)'
739-
const actual = systemUnderTest.removeStorageAndNoteReferences(
740+
const actual = systemUnderTest.replaceStorageReferences(
740741
testInput,
741-
noteKey
742+
noteKey,
743+
systemUnderTest.DESTINATION_FOLDER
742744
)
743745
expect(actual).toEqual(expectedOutput)
744746
})
@@ -803,38 +805,46 @@ it('should replace the all ":storage" references', function() {
803805
' </p>\n' +
804806
' </body>\n' +
805807
'</html>'
806-
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
808+
const actual = systemUnderTest.replaceStorageReferences(
809+
testInput,
810+
noteKey,
811+
systemUnderTest.DESTINATION_FOLDER
812+
)
807813
expect(actual).toEqual(expectedOutput)
808814
})
809815

810816
it('should make sure that "replaceStorageReferences" works with markdown content as well', function() {
811817
const noteKey = 'noteKey'
812818
const testInput =
813819
'Test input' +
814-
'![' +
820+
'![imageName](' +
815821
systemUnderTest.STORAGE_FOLDER_PLACEHOLDER +
816-
path.sep +
822+
path.win32.sep +
817823
noteKey +
818-
path.sep +
819-
'image.jpg](imageName}) \n' +
820-
'[' +
824+
path.win32.sep +
825+
'image.jpg) \n' +
826+
'[pdf](' +
821827
systemUnderTest.STORAGE_FOLDER_PLACEHOLDER +
822-
path.sep +
828+
path.posix.sep +
823829
noteKey +
824-
path.sep +
825-
'pdf.pdf](pdf})'
830+
path.posix.sep +
831+
'pdf.pdf)'
826832

827833
const expectedOutput =
828834
'Test input' +
829-
'![' +
835+
'![imageName](' +
830836
systemUnderTest.DESTINATION_FOLDER +
831-
path.sep +
832-
'image.jpg](imageName}) \n' +
833-
'[' +
837+
path.posix.sep +
838+
'image.jpg) \n' +
839+
'[pdf](' +
834840
systemUnderTest.DESTINATION_FOLDER +
835-
path.sep +
836-
'pdf.pdf](pdf})'
837-
const actual = systemUnderTest.replaceStorageReferences(testInput, noteKey)
841+
path.posix.sep +
842+
'pdf.pdf)'
843+
const actual = systemUnderTest.replaceStorageReferences(
844+
testInput,
845+
noteKey,
846+
systemUnderTest.DESTINATION_FOLDER
847+
)
838848
expect(actual).toEqual(expectedOutput)
839849
})
840850

0 commit comments

Comments
 (0)