Skip to content

Commit

Permalink
validateworkselection() because it was possible for the browser lin…
Browse files Browse the repository at this point in the history
…ks to slip an invalid work selection into the mix
  • Loading branch information
e-gun committed Nov 28, 2023
1 parent d2323d1 commit d712732
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/labstack/echo/v4 v4.11.3
github.com/pkg/profile v1.7.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/text v0.14.0
gonum.org/v1/gonum v0.14.0
)
Expand All @@ -23,7 +23,7 @@ require (
github.com/e-gun/sparse v0.0.0-20230418220937-07063da15582 // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect
github.com/google/pprof v0.0.0-20231127191134-f3a68a39ae15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
Expand All @@ -42,9 +42,9 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
)
2 changes: 2 additions & 0 deletions greekandlatin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func StripaccentsRUNE(u []rune) []rune {
return stripped
}

// SwapAcuteForGrave - ὰ --> ά
func SwapAcuteForGrave(thetext string) string {
swap := strings.NewReplacer("ὰ", "ά", "ὲ", "έ", "ὶ", "ί", "ὸ", "ό", "ὺ", "ύ", "ὴ", "ή", "ὼ", "ώ",
"ἂ", "ἄ", "ἃ", "ἅ", "ᾲ", "ᾴ", "ᾂ", "ᾄ", "ᾃ", "ᾅ", "ἒ", "ἔ", "ἲ", "ἴ", "ὂ", "ὄ", "ὃ", "ὅ", "ὒ", "ὔ", "ὓ", "ὕ",
Expand All @@ -56,6 +57,7 @@ func SwapAcuteForGrave(thetext string) string {
return swap.Replace(thetext)
}

// SwapGraveForAcute - ά --> ὰ
func SwapGraveForAcute(thetext string) string {
swap := strings.NewReplacer("ά", "ὰ", "έ", "ὲ", "ί", "ὶ", "ό", "ὸ", "ύ", "ὺ", "ή", "ὴ", "ώ", "ὼ",
"ἄ", "ἂ", "ἅ", "ἃ", "ᾴ", "ᾲ", "ᾄ", "ᾂ", "ᾅ", "ᾃ", "ἔ", "ἒ", "ἴ", "ἲ", "ὄ", "ὂ", "ὅ", "ὃ", "ὔ", "ὒ", "ὕ", "ὓ",
Expand Down
13 changes: 2 additions & 11 deletions rt-browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,9 @@ func generatebrowsedpassage(au string, wk string, fc int, ctx int) BrowsedPassag
k := fmt.Sprintf("%sw%s", au, wk)

// [a] validate
w := &DbWork{}
w.UID = "null"
if _, ok := AllWorks[k]; ok {
w = AllWorks[k]
} else {
if _, y := AllAuthors[au]; y {
// firstwork; otherwise we are still set to "null"
w = AllWorks[AllAuthors[au].WorkList[0]]
}
}
w := validateworkselection(k)

if w.UID == "null" {
if w.UID == "work_not_found" {
// some problem cases (that arise via rt-lexica.go and the bad clicks embedded in teh lexical data):
// gr0161w001
msg(fmt.Sprintf(FAIL1, k), MSGFYI)
Expand Down
30 changes: 28 additions & 2 deletions rt-selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,11 +734,21 @@ func endpointer(wuid string, locus string, sep string) ([2]int, bool) {
const (
QTMP = `SELECT index FROM %s WHERE wkuniversalid='%s' AND %s ORDER BY index ASC`
FAIL = "endpointer() failed to find the following inside of %s: '%s'"
WNFD = "endpointer() failed to find a work: %2"
)

success := false
fl := [2]int{0, 0}
wk := AllWorks[wuid]
success := false

// dictionary click inside 'τάλαντον' at end of first segment: "...δίκαϲ ῥέπει τάλαντον Bacchylides 17.25."
// error 500: /browse/perseus/gr0199/002/17:25
// but there is no work 002; the numbers start at 010

wk := validateworkselection(wuid)
if wk.UID == "work_not_found" {
msg(fmt.Sprintf(WNFD, wuid), MSGFYI)
return fl, false
}

wl := wk.CountLevels()
ll := strings.Split(locus, sep)
Expand Down Expand Up @@ -934,6 +944,22 @@ func formatnewselectionjs(jsinfo []JSData) string {
return script
}

// validateworkselection - what if you request a work that does not exist? return something...
func validateworkselection(uid string) *DbWork {
w := &DbWork{}
w.UID = "work_not_found"
au := uid[0:6]
if _, ok := AllWorks[uid]; ok {
w = AllWorks[uid]
} else {
if _, y := AllAuthors[au]; y {
// firstwork; otherwise we are still set to "null"
w = AllWorks[AllAuthors[au].WorkList[0]]
}
}
return w
}

// A LIST

//Author categories
Expand Down

0 comments on commit d712732

Please sign in to comment.