From d71273282116144562f00aaf6d2d988556f3c66d Mon Sep 17 00:00:00 2001 From: e-gun Date: Mon, 27 Nov 2023 21:19:45 -0500 Subject: [PATCH] `validateworkselection()` because it was possible for the browser links to slip an invalid work selection into the mix --- go.mod | 12 ++++++------ greekandlatin.go | 2 ++ rt-browser.go | 13 ++----------- rt-selection.go | 30 ++++++++++++++++++++++++++++-- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 7add85b..e1de586 100644 --- a/go.mod +++ b/go.mod @@ -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 ) @@ -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 @@ -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 ) diff --git a/greekandlatin.go b/greekandlatin.go index 1a0f6a4..5a4a81d 100644 --- a/greekandlatin.go +++ b/greekandlatin.go @@ -48,6 +48,7 @@ func StripaccentsRUNE(u []rune) []rune { return stripped } +// SwapAcuteForGrave - ὰ --> ά func SwapAcuteForGrave(thetext string) string { swap := strings.NewReplacer("ὰ", "ά", "ὲ", "έ", "ὶ", "ί", "ὸ", "ό", "ὺ", "ύ", "ὴ", "ή", "ὼ", "ώ", "ἂ", "ἄ", "ἃ", "ἅ", "ᾲ", "ᾴ", "ᾂ", "ᾄ", "ᾃ", "ᾅ", "ἒ", "ἔ", "ἲ", "ἴ", "ὂ", "ὄ", "ὃ", "ὅ", "ὒ", "ὔ", "ὓ", "ὕ", @@ -56,6 +57,7 @@ func SwapAcuteForGrave(thetext string) string { return swap.Replace(thetext) } +// SwapGraveForAcute - ά --> ὰ func SwapGraveForAcute(thetext string) string { swap := strings.NewReplacer("ά", "ὰ", "έ", "ὲ", "ί", "ὶ", "ό", "ὸ", "ύ", "ὺ", "ή", "ὴ", "ώ", "ὼ", "ἄ", "ἂ", "ἅ", "ἃ", "ᾴ", "ᾲ", "ᾄ", "ᾂ", "ᾅ", "ᾃ", "ἔ", "ἒ", "ἴ", "ἲ", "ὄ", "ὂ", "ὅ", "ὃ", "ὔ", "ὒ", "ὕ", "ὓ", diff --git a/rt-browser.go b/rt-browser.go index 8b77386..ae9460c 100644 --- a/rt-browser.go +++ b/rt-browser.go @@ -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) diff --git a/rt-selection.go b/rt-selection.go index a785b0f..350f848 100644 --- a/rt-selection.go +++ b/rt-selection.go @@ -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) @@ -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