Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix offBy1 errors #17606

Merged
merged 12 commits into from
Nov 14, 2021
6 changes: 5 additions & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func runDocs(ctx *cli.Context) error {
// Clean up markdown. The following bug was fixed in v2, but is present in v1.
// It affects markdown output (even though the issue is referring to man pages)
// https://github.com/urfave/cli/issues/1040
docs = docs[strings.Index(docs, "#"):]
firstHashtagIndex := strings.Index(docs, "#")

if firstHashtagIndex > 0 {
docs = docs[firstHashtagIndex:]
}
}

out := os.Stdout
Expand Down
9 changes: 8 additions & 1 deletion models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package migrations

import (
"context"
"errors"
"fmt"
"os"
"reflect"
Expand Down Expand Up @@ -791,8 +792,14 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
}
tableSQL := string(res[0]["sql"])

// Get the string offset for column definitions: `CREATE TABLE ( column-definitions... )`
columnDefinitionsIndex := strings.Index(tableSQL, "(")
if columnDefinitionsIndex < 0 {
return errors.New("couldn't find column definitions")
}

// Separate out the column definitions
tableSQL = tableSQL[strings.Index(tableSQL, "("):]
tableSQL = tableSQL[columnDefinitionsIndex:]

// Remove the required columnNames
for _, name := range columnNames {
Expand Down