Sanitizing urls to correct common user mistakes: not including the scheme ('http://' or 'https://') or pasting white spaces at the end or url, usually when they come from etherpads or mailing.

This closes ticket http://mutabit.com/repos.fossil/grafoscopio/tktview?name=c7fe88f9ca .
This commit is contained in:
Offray Vladimir Luna Cárdenas 2017-08-10 13:27:10 +00:00
parent f251c55464
commit a670787ef3
2 changed files with 32 additions and 31 deletions

View File

@ -288,6 +288,13 @@ GrafoscopioNode >> bodyAsMarkdownInto: aStream [
self embeddedNodes ifNotNil: [ aStream nextPutAll: (self embedNodes contents asString withInternetLineEndings); crlf; crlf]. self embeddedNodes ifNotNil: [ aStream nextPutAll: (self embedNodes contents asString withInternetLineEndings); crlf; crlf].
] ]
{ #category : #operation }
GrafoscopioNode >> checksum [
"I return the SHA1SUM of the current tree. I'm used to test changes on the contents
and for traceability of how the document tree is converted to other formats, as markdown."
^ (SHA1 new hashMessage: self root flatten asSton) hex
]
{ #category : #accessing } { #category : #accessing }
GrafoscopioNode >> children [ GrafoscopioNode >> children [
"Returns the receivers list of children" "Returns the receivers list of children"
@ -326,13 +333,6 @@ GrafoscopioNode >> copyToClipboard [
] ]
{ #category : #operation }
GrafoscopioNode >> cryptoSignature [
"I return the SHA1SUM of the current tree. I'm used to test changes on the contents
and for traceability of how the document tree is converted to other formats, as markdown."
^ (SHA1 new hashMessage: self root flatten asSton) hex
]
{ #category : #utility } { #category : #utility }
GrafoscopioNode >> deleteReferencesToRoot: aRootNode [ GrafoscopioNode >> deleteReferencesToRoot: aRootNode [
@ -735,7 +735,7 @@ GrafoscopioNode >> metadataAsYamlIn: markdownStream [
markdownStream markdownStream
nextPutAll: '---'; nextPutAll: '---';
lf; lf;
nextPutAll: 'exportedFrom: ', self cryptoSignature; nextPutAll: 'exportedFrom: ', self checksum;
lf. lf.
self metadata self metadata
ifNotNil: [ ifNotNil: [
@ -937,8 +937,10 @@ GrafoscopioNode >> tags [
ifTrue: [ ifTrue: [
migration := tags. migration := tags.
tags := OrderedCollection new. tags := OrderedCollection new.
tags add: migration ]. self tagAs: migration ].
tags ifNil: [ tags := OrderedCollection new ]. tags ifNil: [
tags := OrderedCollection new.
self tagAs: 'text' ].
^ tags ^ tags
] ]

View File

@ -89,14 +89,8 @@ GrafoscopioNotebook >> body: anObject [
body := anObject body := anObject
] ]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> copyNodeToClipboard [
tree highlightedItem content copyToClipboard.
self notebookContent: notebook.
]
{ #category : #utilities } { #category : #utilities }
GrafoscopioNotebook >> cryptoSignature [ GrafoscopioNotebook >> checksum [
"I return the cryptographic signature of the workingFile where this notebook is being stored. "I return the cryptographic signature of the workingFile where this notebook is being stored.
I'm useful for data provenance and traceability of derivated files related with this source I'm useful for data provenance and traceability of derivated files related with this source
notebook." notebook."
@ -105,6 +99,12 @@ GrafoscopioNotebook >> cryptoSignature [
^ (SHA1 new hashMessage: (self workingFile contents)) hex. ^ (SHA1 new hashMessage: (self workingFile contents)) hex.
] ]
{ #category : #'editing nodes' }
GrafoscopioNotebook >> copyNodeToClipboard [
tree highlightedItem content copyToClipboard.
self notebookContent: notebook.
]
{ #category : #'editing nodes' } { #category : #'editing nodes' }
GrafoscopioNotebook >> cutNodeToClipboard [ GrafoscopioNotebook >> cutNodeToClipboard [
self copyNodeToClipboard; removeNode. self copyNodeToClipboard; removeNode.
@ -275,7 +275,7 @@ GrafoscopioNotebook >> initializePresenter [
header whenTextChanged: [ :arg | header whenTextChanged: [ :arg |
(tree highlightedItem content header) = arg (tree highlightedItem content header) = arg
ifFalse: [ ifFalse: [
(tree highlightedItem) content header: arg. tree highlightedItem content header: arg.
tree roots: tree roots]]. tree roots: tree roots]].
links whenTextChanged: [ :arg | tree highlightedItem content addLink: arg ] links whenTextChanged: [ :arg | tree highlightedItem content addLink: arg ]
] ]
@ -475,13 +475,14 @@ GrafoscopioNotebook >> openFromFileSelector [
] ]
{ #category : #persistence } { #category : #persistence }
GrafoscopioNotebook >> openFromUrl: anUrl [ GrafoscopioNotebook >> openFromUrl: url [
"Opens a tree from a file named aFileName" "Opens a tree from a file named aFileName"
| fileName | | fileName sanitized |
fileName := (anUrl splitOn: '/') last. sanitized := GrafoscopioUtils sanitize: url.
fileName := sanitized segments last.
GrafoscopioUtils GrafoscopioUtils
downloadingFrom: anUrl downloadingFrom: sanitized
withMessage: 'Downloading document...' withMessage: 'Downloading document...'
into: FileLocator temp. into: FileLocator temp.
self class new openFromFile: (FileLocator temp / fileName) self class new openFromFile: (FileLocator temp / fileName)
@ -570,18 +571,16 @@ GrafoscopioNotebook >> removeNode [
{ #category : #persistence } { #category : #persistence }
GrafoscopioNotebook >> saveToFile: aFileReference [ GrafoscopioNotebook >> saveToFile: aFileReference [
"I save the current tree/document to a file" "I save the current tree/document to a file."
aFileReference ifNil: [ self inform: 'No file selected for saving. Save NOT done'. ^ self ]. aFileReference ifNil: [ self inform: 'No file selected for saving. Save NOT done'. ^ self ].
workingFile := aFileReference. workingFile := aFileReference.
self workingFile exists ifTrue: [self workingFile delete]. self workingFile ensureDelete.
self workingFile ensureCreateFile. self workingFile writeStreamDo: [:stream |
[ self exportAsSton: self notebook on: (self workingFile writeStream)] self exportAsSton: self notebook on:stream ].
ensure: [ (self workingFile writeStream) ifNotNil: #close ].
self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'. self title: self workingFile basenameWithIndicator, ' | Grafoscopio notebook'.
self inform: ('File saved at: ', String cr, self workingFile fullName). self inform: ('File saved at: ', String cr, self workingFile fullName).
GrafoscopioDockingBar updateRecentNotebooksWith: aFileReference. GrafoscopioDockingBar updateRecentNotebooksWith: aFileReference.
] ]
{ #category : #persistence } { #category : #persistence }
@ -748,7 +747,7 @@ GrafoscopioNotebook >> topBar [
addItem: [ :item | addItem: [ :item |
item item
name: nil; name: nil;
description: 'Reload link'; description: 'Import link content';
icon: #glamorousRefresh asIcon; icon: #glamorousRefresh asIcon;
action: [ self importLinkContent ] ]. action: [ self importLinkContent ] ].
group group