Fix webmention verification

This commit is contained in:
Jan-Lukas Else 2021-06-29 23:19:58 +02:00
parent 4c5e77dcab
commit 597dc35470
2 changed files with 6 additions and 6 deletions

View File

@ -86,7 +86,7 @@ func extractMention(r *http.Request) (*mention, error) {
func (db *database) webmentionExists(source, target string) bool {
result := 0
row, err := db.queryRow("select exists(select 1 from webmentions where source = ? and target = ?)", source, target)
row, err := db.queryRow("select exists(select 1 from webmentions where lower(source) = lower(@source) and lower(target) = lower(@target))", sql.Named("source", source), sql.Named("target", target))
if err != nil {
return false
}
@ -143,7 +143,7 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
if config != nil {
filter = "where 1 = 1"
if config.target != "" {
filter += " and target = @target"
filter += " and lower(target) = lower(@target)"
args = append(args, sql.Named("target", config.target))
}
if config.status != "" {
@ -151,8 +151,8 @@ func buildWebmentionsQuery(config *webmentionsRequestConfig) (query string, args
args = append(args, sql.Named("status", config.status))
}
if config.sourcelike != "" {
filter += " and source like @sourcelike"
args = append(args, sql.Named("sourcelike", "%"+config.sourcelike+"%"))
filter += " and lower(source) like @sourcelike"
args = append(args, sql.Named("sourcelike", "%"+strings.ToLower(config.sourcelike)+"%"))
}
if config.id != 0 {
filter += " and id = @id"

View File

@ -98,7 +98,7 @@ func (a *goBlog) verifyMention(m *mention) error {
}
newStatus := webmentionStatusVerified
if a.db.webmentionExists(m.Source, m.Target) {
_, err = a.db.exec("update webmentions set status = @status, title = @title, content = @content, author = @author where source = @source and target = @target",
_, err = a.db.exec("update webmentions set status = @status, title = @title, content = @content, author = @author where lower(source) = lower(@source) and lower(target) = lower(@target)",
sql.Named("status", newStatus), sql.Named("title", m.Title), sql.Named("content", m.Content), sql.Named("author", m.Author), sql.Named("source", m.Source), sql.Named("target", m.Target))
} else {
_, err = a.db.exec("insert into webmentions (source, target, created, status, title, content, author) values (@source, @target, @created, @status, @title, @content, @author)",
@ -156,7 +156,7 @@ func (m *mention) fill(mf *microformats.Microformat) bool {
// Check URL
if url, ok := mf.Properties["url"]; ok && len(url) > 0 {
if url0, ok := url[0].(string); ok {
if url0 != m.Source {
if strings.ToLower(url0) != strings.ToLower(m.Source) {
// Not correct URL
return false
}