fix a regression with not normalising titles to lowercase/trim
This commit is contained in:
parent
fc57e4d8f3
commit
5cc93387e7
12
DB.go
12
DB.go
@ -3,6 +3,7 @@ package yatwiki
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
@ -103,6 +104,10 @@ func (aae ArticleAlteredError) Error() string {
|
||||
return fmt.Sprintf("Warning: Your changes were not based on the most recent version of the page (r%d ≠ r%d). No changes were saved.", aae.got, aae.expected)
|
||||
}
|
||||
|
||||
func (this *WikiDB) normaliseTitle(title string) string {
|
||||
return strings.ToLower(strings.Trim(title, " \r\n\t"))
|
||||
}
|
||||
|
||||
func (this *WikiDB) SaveArticle(title, author, body string, expectBaseRev int64) error {
|
||||
isNewArticle := false
|
||||
a, err := this.GetLatestVersion(title)
|
||||
@ -125,7 +130,7 @@ func (this *WikiDB) SaveArticle(title, author, body string, expectBaseRev int64)
|
||||
|
||||
var titleId int64
|
||||
if isNewArticle {
|
||||
titleInsert, err := this.db.Exec(`INSERT INTO titles (title) VALUES (?)`, title)
|
||||
titleInsert, err := this.db.Exec(`INSERT INTO titles (title) VALUES (?)`, this.normaliseTitle(title))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -147,7 +152,10 @@ func (this *WikiDB) SaveArticle(title, author, body string, expectBaseRev int64)
|
||||
}
|
||||
|
||||
func (this *WikiDB) GetRevisionHistory(title string) ([]Article, error) {
|
||||
rows, err := this.db.Query(`SELECT articles.id, articles.modified, articles.author FROM articles WHERE article = (SELECT id FROM titles WHERE title = ?) ORDER BY modified DESC`, title)
|
||||
rows, err := this.db.Query(
|
||||
`SELECT articles.id, articles.modified, articles.author FROM articles WHERE article = (SELECT id FROM titles WHERE title = ?) ORDER BY modified DESC`,
|
||||
this.normaliseTitle(title),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user