Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #3190 from Sh1d0w/hotfix/issue-3188
Browse files Browse the repository at this point in the history
Validate bookmark name before creation Fixes #3188
  • Loading branch information
bbondy authored Aug 17, 2016
2 parents b1f14a3 + 2ac4180 commit 3757ac5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/components/addEditBookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ class AddEditBookmark extends ImmutableComponent {
this.onSave = this.onSave.bind(this)
this.onRemoveBookmark = this.onRemoveBookmark.bind(this)
}

get isBlankTab () {
return ['about:blank', 'about:newtab'].includes(this.props.currentDetail.get('location'))
}

get bookmarkNameValid () {
return (this.props.currentDetail.get('title') || this.props.currentDetail.get('customTitle'))
}

get isFolder () {
return siteUtil.isFolder(this.props.currentDetail)
}
Expand Down Expand Up @@ -68,6 +74,7 @@ class AddEditBookmark extends ImmutableComponent {
} else {
currentDetail = currentDetail.set('customTitle', e.target.value)
}

windowActions.setBookmarkDetail(currentDetail, this.props.originalDetail, this.props.destinationDetail)
}
onLocationChange (e) {
Expand All @@ -79,6 +86,11 @@ class AddEditBookmark extends ImmutableComponent {
windowActions.setBookmarkDetail(currentDetail, this.props.originalDetail, this.props.destinationDetail)
}
onSave () {
// First check if the title of the currentDetail is set
if (!this.bookmarkNameValid) {
return false
}

const tag = this.isFolder ? siteTags.BOOKMARK_FOLDER : siteTags.BOOKMARK
appActions.addSite(this.props.currentDetail, tag, this.props.originalDetail, this.props.destinationDetail)
this.onClose()
Expand All @@ -91,7 +103,7 @@ class AddEditBookmark extends ImmutableComponent {
if (this.props.currentDetail.get('customTitle') !== undefined) {
return this.props.currentDetail.get('customTitle')
}
return this.props.currentDetail.get('title')
return this.props.currentDetail.get('title') || ''
}
render () {
return <Dialog onHide={this.onClose} isClickDismiss>
Expand Down Expand Up @@ -125,7 +137,7 @@ class AddEditBookmark extends ImmutableComponent {
? <a data-l10n-id='delete' className='removeBookmarkLink link' onClick={this.onRemoveBookmark} />
: null
}
<Button l10nId='save' className='primaryButton' onClick={this.onSave} />
<Button l10nId='save' className={this.bookmarkNameValid ? 'primaryButton' : 'primaryButton disabled'} onClick={this.onSave} />
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions less/addEditBookmark.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.removeBookmarkLink {
margin-right: auto;
}

.disabled {
background-color: #ccc !important;
}

0 comments on commit 3757ac5

Please sign in to comment.