diff --git a/.github/workflows/vendored-provenance.yml b/.github/workflows/vendored-provenance.yml index ccbcc41..db9382d 100644 --- a/.github/workflows/vendored-provenance.yml +++ b/.github/workflows/vendored-provenance.yml @@ -132,14 +132,15 @@ jobs: exit 1 fi - # The gate that actually keeps a green build meaningful for topaz-1. + # Keeps the two avl roles from being confused. # - # GNOVERSION is NOT topaz-1's ref, so ~15 vendored packages differ from what - # the chain hosts — including p/nt/avl/v0, whose on-chain Get is SINGLE-value - # while the vendored copy is two-value. That is safe today for exactly one - # reason: gnodaokit crosses that boundary only via ntavl.NewTree(), whose - # signature is identical in both. Nothing else enforced that, so a single new - # ntavl.Get() call would compile green here and fail AddPackage on-chain. + # The stdlib p/nt/avl/v0 is here only because svg.Canvas.Style is a + # *nt/avl/v0.Tree; the data-structure role belongs to the p/samcrew/avl fork, + # whose Get is two-value. GNOVERSION is now topaz-1's own ref, so the vendored + # stdlib copy matches the chain and a misuse fails the build directly — this + # gate exists to say WHY it failed, and to keep the boundary from widening by + # accident. When the pin was older than the chain, this was the only thing + # standing between a green build and a failed AddPackage. - name: The stdlib-avl boundary must stay limited to NewTree run: | set -euo pipefail @@ -153,9 +154,9 @@ jobs: if [[ -n "$unexpected" ]]; then echo "ERROR: gnodaokit uses the stdlib avl beyond NewTree:" printf '%s\n' "$unexpected" - echo "topaz-1's p/nt/avl/v0 Get is SINGLE-value while the vendored copy is" - echo "two-value, so this would compile here and fail AddPackage on-chain." - echo "Use gno.land/p/samcrew/avl instead, or re-verify against topaz-1." + echo "The stdlib avl is vendored only for the svg.Canvas.Style ABI; its Get" + echo "is single-value on topaz-1 and here. Use gno.land/p/samcrew/avl for" + echo "data structures — that is the fork with the two-value Get." exit 1 fi echo "stdlib avl boundary is limited to NewTree, as required" diff --git a/Makefile b/Makefile index b891483..6dd1c56 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GNOVERSION=2c7f1abe324e8fa6fac6dc71a36635cc4e92a0be +GNOVERSION=fc40526511474e40b8a66419f5ba28255085bc08 GNO=go run github.com/gnolang/gno/gnovm/cmd/gno@${GNOVERSION} .PHONY: dev diff --git a/vendored/README.md b/vendored/README.md index 5f7adba..f6257bd 100644 --- a/vendored/README.md +++ b/vendored/README.md @@ -42,23 +42,30 @@ topaz-1's stdlib `p/nt/avl/v0` exposes a **single-value** `Get`, while this code **green build compiled against an ABI the target chain does not have** — a false green in exactly the place the gate exists to prevent one. So the fork is vendored for that role. -### ⚠️ A green build here does not by itself prove "publishable on topaz-1" - -`GNOVERSION` is **not** topaz-1's ref. The chain runs `fc4052651`; the `Makefile` pins `2c7f1abe`. -Roughly 15 vendored packages therefore differ from what the chain actually hosts — **including -`p/nt/avl/v0`, whose on-chain `Get` is single-value while the vendored copy is two-value.** - -Do not read the vendored tree as a mirror of topaz-1. It is version-matched to the **compiler**, and -that is all the provenance job proves. - -What makes it safe today is narrower and worth stating exactly: gnodaokit crosses the stdlib-avl -boundary in exactly one place — `ntavl` in `gno/p/basedao/utils.gno`, because `svg.Canvas.Style` is -a `*nt/avl/v0.Tree` — and it calls only `NewTree()`, whose signature is identical in both. A single -new `ntavl.Get()` call would compile green here and fail `AddPackage` on-chain. - -CI enforces precisely that invariant (`vendored-provenance.yml`, "The stdlib-avl boundary must stay -limited to NewTree"). Widening the boundary, or bumping `GNOVERSION`, means re-checking the exported -surface of every skewed package against the chain — not just re-running the build. +### `GNOVERSION` is topaz-1's own ref + +`GNOVERSION` is `fc4052651`, which is what topaz-1 runs. The vendored tree is therefore +version-matched to the compiler **and** to the chain at the same time, so a green build here does +correspond to what `AddPackage` will see — for the stdlib dependencies. It still says nothing about +`p/samcrew/*`, which no chain hosts until the ceremony publishes it (see Sequencing). + +It was not always so. The pin used to be `2c7f1abe`, six weeks older, and roughly 15 vendored +packages differed from what the chain hosted — **including `p/nt/avl/v0`, whose on-chain `Get` is +single-value while the vendored copy at that ref was two-value.** A green build genuinely did not +prove publishability, and the gap was held open only by a narrow argument about which symbols +gnodaokit actually touched. Two concrete costs, both paid: the old toolchain had **no sub-realm +support at all** — `cur.Sub()` failed preprocessing — so nothing could test the semantics the +identity work reasons about; and the divergence had to be re-argued by hand on every change. + +gnodaokit still crosses the stdlib-avl boundary in exactly one place — `ntavl` in +`gno/p/basedao/utils.gno`, because `svg.Canvas.Style` is a `*nt/avl/v0.Tree` — and calls only +`NewTree()`. CI keeps enforcing that (`vendored-provenance.yml`, "The stdlib-avl boundary must stay +limited to NewTree"), but the invariant is now belt-and-braces rather than load-bearing: with the +vendored copy matching the chain, an `ntavl.Get()` two-value call fails **locally**, at build time, +instead of surviving to `AddPackage`. + +Bumping `GNOVERSION` again re-opens all of this. Whoever does it must re-run the regeneration below +and re-check that the new ref is still what the target chain runs. ### Sequencing diff --git a/vendored/gno.land/p/moul/md/example_test.gno b/vendored/gno.land/p/moul/md/example_test.gno new file mode 100644 index 0000000..5729fbc --- /dev/null +++ b/vendored/gno.land/p/moul/md/example_test.gno @@ -0,0 +1,207 @@ +package md + +import "strings" + +func ExampleHeaders() { + println(H1("Header 1")) + println(H2("Header 2")) + println(H3("Header 3")) + println(H4("Header 4")) + println(H5("Header 5")) + println(H6("Header 6")) + + // Output: + // # Header 1 + // + // ## Header 2 + // + // ### Header 3 + // + // #### Header 4 + // + // ##### Header 5 + // + // ###### Header 6 +} + +func ExampleStyles() { + println(Bold("bold")) + println(Italic("italic")) + println(Strikethrough("strikethrough")) + + // Output: + // **bold** + // *italic* + // ~~strikethrough~~ +} + +func ExampleLists() { + println(BulletList([]string{ + "Item 1", + "Item 2\nMore details for item 2", + })) + println(OrderedList([]string{"Step 1", "Step 2"})) + println(TodoList([]string{"Task 1", "Task 2\nSubtask 2"}, []bool{true, false})) + println(Nested(BulletList([]string{"Parent Item", OrderedList([]string{"Child 1", "Child 2"})}), " ")) + + // Output: + // - Item 1 + // - Item 2 + // More details for item 2 + // + // 1. Step 1 + // 2. Step 2 + // + // - [x] Task 1 + // - [ ] Task 2 + // Subtask 2 + // + // - Parent Item + // - 1. Child 1 + // 2. Child 2 +} + +func ExampleBlocks() { + print(Paragraph("This is a paragraph.")) + // Blockquote adds multiple newlines which Output doesn't allow, so trim + println(strings.TrimSpace(Blockquote("This is a blockquote\nSpanning multiple lines"))) + + // Output: + // This is a paragraph. + // + // > This is a blockquote + // > Spanning multiple lines +} + +func ExampleCode() { + println(InlineCode("inline `code`")) + println(CodeBlock("line1\nline2")) + println(LanguageCodeBlock("go", "func main() {\nprintln(\"Hello, world!\")\n}")) + println(HorizontalRule()) + + // Output: + // `` inline `code` `` + // ``` + // line1 + // line2 + // ``` + // + // ```go + // func main() { + // println("Hello, world!") + // } + // ``` + // + // --- +} + +func ExampleReferences() { + println(Link("Gno", "http://gno.land")) + println(Image("Alt Text", "http://example.com/image.png")) + println(InlineImageWithLink("Alt Text", "http://example.com/image.png", "http://example.com")) + println(FootnoteDefinition("ref", "This is a footnote")) + // LinkReferenceDefinition adds multiple newlines which Output doesn't allow, so trim + println(strings.TrimSpace(LinkReferenceDefinition("r-example", "/r/example", ""))) + + // Output: + // + // [Gno](http://gno.land) + // ![Alt Text](http://example.com/image.png) + // [![Alt Text](http://example.com/image.png)](http://example.com) + // [^ref]: + // This is a footnote + // + // [r-example]: /r/example +} + +func ExampleColumns() { + println("4 columns in one gno-columns tag:") + println(Columns([]string{ + "Column1\ncontent1", + "Column2\ncontent2", + "Column3\ncontent3", + "Column4\ncontent4", + }, true)) + + // Should be automatically placed in multiple column tags + println("3 cols per row without padding:") + println(ColumnsN([]string{ + "Row1Column1\ncontent1", + "Row1Column2\ncontent2", + "Row1Column3\ncontent3", + "Row2Column1\ncontent1", + "Row2Column2\ncontent2", + "Row2Column3\ncontent3", + "Row3Column1\ncontent1", + "Row3Column2\ncontent2", + "Row3Column3\ncontent3", + }, 3, false)) + + // Should be padded, up to 4 cols + println("2 padded to 4:") + println(ColumnsN([]string{ + "Column1\ncontent1", + "Column2\ncontent2", + }, 4, true)) + + // Output: + // 4 columns in one gno-columns tag: + // + // Column1 + // content1 + // + // Column2 + // content2 + // + // Column3 + // content3 + // + // Column4 + // content4 + // + // + // 3 cols per row without padding: + // + // Row1Column1 + // content1 + // + // Row1Column2 + // content2 + // + // Row1Column3 + // content3 + // + // + // Row2Column1 + // content1 + // + // Row2Column2 + // content2 + // + // Row2Column3 + // content3 + // + // + // Row3Column1 + // content1 + // + // Row3Column2 + // content2 + // + // Row3Column3 + // content3 + // + // + // 2 padded to 4: + // + // Column1 + // content1 + // + // Column2 + // content2 + // + // + // + // + // +} diff --git a/vendored/gno.land/p/moul/md/filetests/z1_filetest.gno b/vendored/gno.land/p/moul/md/filetests/z1_filetest.gno deleted file mode 100644 index e3119cd..0000000 --- a/vendored/gno.land/p/moul/md/filetests/z1_filetest.gno +++ /dev/null @@ -1,188 +0,0 @@ -package main - -import "gno.land/p/moul/md" - -func main() { - println(md.H1("Header 1")) - println(md.H2("Header 2")) - println(md.H3("Header 3")) - println(md.H4("Header 4")) - println(md.H5("Header 5")) - println(md.H6("Header 6")) - println(md.Bold("bold")) - println(md.Italic("italic")) - println(md.Strikethrough("strikethrough")) - println(md.BulletList([]string{ - "Item 1", - "Item 2\nMore details for item 2", - })) - println(md.OrderedList([]string{"Step 1", "Step 2"})) - println(md.TodoList([]string{"Task 1", "Task 2\nSubtask 2"}, []bool{true, false})) - println(md.Nested(md.BulletList([]string{"Parent Item", md.OrderedList([]string{"Child 1", "Child 2"})}), " ")) - println(md.Blockquote("This is a blockquote\nSpanning multiple lines")) - println(md.InlineCode("inline `code`")) - println(md.CodeBlock("line1\nline2")) - println(md.LanguageCodeBlock("go", "func main() {\nprintln(\"Hello, world!\")\n}")) - println(md.HorizontalRule()) - println(md.Link("Gno", "http://gno.land")) - println(md.Image("Alt Text", "http://example.com/image.png")) - println(md.InlineImageWithLink("Alt Text", "http://example.com/image.png", "http://example.com")) - println(md.FootnoteDefinition("ref", "This is a footnote")) - println(md.LinkReferenceDefinition("r-example", "/r/example", "")) - println(md.Paragraph("This is a paragraph.")) - - println("4 columns in one gno-columns tag:") - println(md.Columns([]string{ - "Column1\ncontent1", - "Column2\ncontent2", - "Column3\ncontent3", - "Column4\ncontent4", - }, true)) - - // Should be automatically placed in multiple column tags - println("3 cols per row without padding:") - println(md.ColumnsN([]string{ - "Row1Column1\ncontent1", - "Row1Column2\ncontent2", - "Row1Column3\ncontent3", - "Row2Column1\ncontent1", - "Row2Column2\ncontent2", - "Row2Column3\ncontent3", - "Row3Column1\ncontent1", - "Row3Column2\ncontent2", - "Row3Column3\ncontent3", - }, 3, false)) - - // Should be padded, up to 4 cols - println("2 padded to 4:") - println(md.ColumnsN([]string{ - "Column1\ncontent1", - "Column2\ncontent2", - }, 4, true)) - -} - -// Output: -// # Header 1 -// -// ## Header 2 -// -// ### Header 3 -// -// #### Header 4 -// -// ##### Header 5 -// -// ###### Header 6 -// -// **bold** -// *italic* -// ~~strikethrough~~ -// - Item 1 -// - Item 2 -// More details for item 2 -// -// 1. Step 1 -// 2. Step 2 -// -// - [x] Task 1 -// - [ ] Task 2 -// Subtask 2 -// -// - Parent Item -// - 1. Child 1 -// 2. Child 2 -// -// -// -// > This is a blockquote -// > Spanning multiple lines -// -// -// `` inline `code` `` -// ``` -// line1 -// line2 -// ``` -// -// ```go -// func main() { -// println("Hello, world!") -// } -// ``` -// -// --- -// -// [Gno](http://gno.land) -// ![Alt Text](http://example.com/image.png) -// [![Alt Text](http://example.com/image.png)](http://example.com) -// [^ref]: -// This is a footnote -// -// -// -// [r-example]: /r/example -// -// -// This is a paragraph. -// -// -// 4 columns in one gno-columns tag: -// -// Column1 -// content1 -// -// Column2 -// content2 -// -// Column3 -// content3 -// -// Column4 -// content4 -// -// -// 3 cols per row without padding: -// -// Row1Column1 -// content1 -// -// Row1Column2 -// content2 -// -// Row1Column3 -// content3 -// -// -// Row2Column1 -// content1 -// -// Row2Column2 -// content2 -// -// Row2Column3 -// content3 -// -// -// Row3Column1 -// content1 -// -// Row3Column2 -// content2 -// -// Row3Column3 -// content3 -// -// -// 2 padded to 4: -// -// Column1 -// content1 -// -// Column2 -// content2 -// -// -// -// -// diff --git a/vendored/gno.land/p/nt/avl/v0/README.md b/vendored/gno.land/p/nt/avl/v0/README.md index fd772e1..cc5506e 100644 --- a/vendored/gno.land/p/nt/avl/v0/README.md +++ b/vendored/gno.land/p/nt/avl/v0/README.md @@ -24,16 +24,20 @@ func Set(key string, value int) { } func Get(key string) int { - // tree.Get returns the value at given key in its raw form, - // and a bool to signify the existence of the key-value pair - rawValue, exists := tree.Get(key) - if !exists { + // tree.Get returns the value at given key, or nil if the key does not exist. + // Use a type assertion to convert the raw value into the proper type. + rawValue := tree.Get(key) + if rawValue == nil { panic("value at given key does not exist") } - // rawValue needs to be converted into the proper type before returning it return rawValue.(int) } + +func Exists(key string) bool { + // tree.Has returns true if the key exists, without retrieving the value. + return tree.Has(key) +} ``` ## Storage Architecture: AVL Tree vs Map diff --git a/vendored/gno.land/p/nt/avl/v0/node.gno b/vendored/gno.land/p/nt/avl/v0/node.gno index adfe8d8..3b77691 100644 --- a/vendored/gno.land/p/nt/avl/v0/node.gno +++ b/vendored/gno.land/p/nt/avl/v0/node.gno @@ -108,12 +108,15 @@ func (node *Node) Get(key string) (index int, value any, exists bool) { // GetByIndex retrieves the key-value pair of the node at the given index // in the subtree rooted at the node. func (node *Node) GetByIndex(index int) (key string, value any) { + if index < 0 { + panic("GetByIndex: negative index not allowed") + } + if node.height == 0 { - if index == 0 { - return node.key, node.value - } else { + if index != 0 { panic("GetByIndex asked for invalid index") } + return node.key, node.value } else { // TODO: could improve this by storing the sizes leftNode := node.getLeftNode() @@ -382,6 +385,12 @@ func (node *Node) TraverseByOffset(offset, limit int, ascending bool, leavesOnly return false } + // Clamp negative offset to 0; otherwise `delta := first.size - offset` + // over-counts and silently drops nodes. + if offset < 0 { + offset = 0 + } + // fast paths. these happen only if TraverseByOffset is called directly on a leaf. if limit <= 0 || offset >= node.size { return false diff --git a/vendored/gno.land/p/nt/avl/v0/node_test.gno b/vendored/gno.land/p/nt/avl/v0/node_test.gno index c90a028..458c882 100644 --- a/vendored/gno.land/p/nt/avl/v0/node_test.gno +++ b/vendored/gno.land/p/nt/avl/v0/node_test.gno @@ -79,6 +79,28 @@ Browser` } } +func TestTraverseByOffsetNegativeOffset(t *testing.T) { + // a negative offset must be treated as 0, not silently drop the right + // subtree. building {"a","b","c","d"} yields a tree whose root has two + // inner children, exercising the traverseByOffset delta computation. + keys := []string{"a", "b", "c", "d"} + r := NewNode(keys[0], nil) + for _, k := range keys[1:] { + r, _ = r.Set(k, nil) + } + + for _, offset := range []int{-1, -2, -100} { + var got []string + r.TraverseByOffset(offset, len(keys), true, true, func(n *Node) bool { + got = append(got, n.Key()) + return false + }) + if !slicesEqual(keys, got) { + t.Errorf("offset %d: want %v got %v", offset, keys, got) + } + } +} + func TestHas(t *testing.T) { tests := []struct { name string diff --git a/vendored/gno.land/p/nt/avl/v0/pager/pager.gno b/vendored/gno.land/p/nt/avl/v0/pager/pager.gno index 4520921..9a4ed44 100644 --- a/vendored/gno.land/p/nt/avl/v0/pager/pager.gno +++ b/vendored/gno.land/p/nt/avl/v0/pager/pager.gno @@ -53,6 +53,10 @@ func (p *Pager) GetPage(pageNumber int) *Page { } func (p *Pager) GetPageWithSize(pageNumber, pageSize int) *Page { + if pageSize <= 0 { + panic("GetPageWithSize: invalid page size") + } + totalItems := p.Tree.Size() totalPages := int(math.Ceil(float64(totalItems) / float64(pageSize))) @@ -63,11 +67,6 @@ func (p *Pager) GetPageWithSize(pageNumber, pageSize int) *Page { Pager: p, } - // pages without content - if pageSize < 1 { - return page - } - // page number provided is not available if pageNumber < 1 { page.HasNext = totalPages > 0 diff --git a/vendored/gno.land/p/nt/avl/v0/rotree/rotree.gno b/vendored/gno.land/p/nt/avl/v0/rotree/rotree.gno index 10882f3..ade6a90 100644 --- a/vendored/gno.land/p/nt/avl/v0/rotree/rotree.gno +++ b/vendored/gno.land/p/nt/avl/v0/rotree/rotree.gno @@ -35,7 +35,7 @@ // PublicTree := rotree.Wrap(tree, makeEntrySafeFn) // // // Safely access the data -// value, _ := roTree.Get("alice") +// value := roTree.Get("alice") // user := value.(*User) // // user.Name == "Alice" // // user.Balance == 100 @@ -86,7 +86,7 @@ type ReadOnlyTree struct { type IReadOnlyTree interface { Size() int Has(key string) bool - Get(key string) (any, bool) + Get(key string) any GetByIndex(index int) (string, any) Iterate(start, end string, cb avl.IterCbFn) bool ReverseIterate(start, end string, cb avl.IterCbFn) bool @@ -119,12 +119,15 @@ func (roTree *ReadOnlyTree) Has(key string) bool { } // Get retrieves the value associated with the given key, converted to a safe format. -func (roTree *ReadOnlyTree) Get(key string) (any, bool) { - value, exists := roTree.tree.Get(key) - if !exists { - return nil, false +// It returns the value if the key exists, or nil if it doesn't. +// Note that a key stored with a nil value is indistinguishable +// from an absent key; use Has to check for existence. +func (roTree *ReadOnlyTree) Get(key string) any { + value := roTree.tree.Get(key) + if value == nil { + return nil } - return roTree.getSafeValue(value), true + return roTree.getSafeValue(value) } // GetByIndex retrieves the key-value pair at the specified index in the tree, with the value converted to a safe format. diff --git a/vendored/gno.land/p/nt/avl/v0/rotree/rotree_test.gno b/vendored/gno.land/p/nt/avl/v0/rotree/rotree_test.gno index 6a63a66..06830fa 100644 --- a/vendored/gno.land/p/nt/avl/v0/rotree/rotree_test.gno +++ b/vendored/gno.land/p/nt/avl/v0/rotree/rotree_test.gno @@ -49,8 +49,8 @@ func TestExample(t *testing.T) { // Test retrieving and verifying a user t.Run("Get User", func(t *testing.T) { // Get user from read-only tree - value, exists := roTree.Get("alice") - if !exists { + value := roTree.Get("alice") + if value == nil { t.Fatal("User 'alice' not found") } @@ -67,7 +67,7 @@ func TestExample(t *testing.T) { } // Verify it's a different instance than the original - originalValue, _ := tree.Get("alice") + originalValue := tree.Get("alice") originalUser := originalValue.(*User) if user == originalUser { t.Error("Read-only tree should return a copy, not the original pointer") @@ -94,7 +94,7 @@ func TestExample(t *testing.T) { // Verify that modifications to the returned user don't affect the original t.Run("Modification Safety", func(t *testing.T) { - value, _ := roTree.Get("alice") + value := roTree.Get("alice") user := value.(*User) // Try to modify the returned user @@ -102,7 +102,7 @@ func TestExample(t *testing.T) { user.Internal = "hacked" // Verify original is unchanged - originalValue, _ := tree.Get("alice") + originalValue := tree.Get("alice") originalUser := originalValue.(*User) if originalUser.Balance != 100 || originalUser.Internal != "sensitive_data_1" { t.Error("Original user data was modified") @@ -127,18 +127,17 @@ func TestReadOnlyTree(t *testing.T) { name string key string expected any - exists bool }{ - {"ExistingKey1", "key1", "value1_readonly", true}, - {"ExistingKey2", "key2", "value2_readonly", true}, - {"NonExistingKey", "key4", nil, false}, + {"ExistingKey1", "key1", "value1_readonly"}, + {"ExistingKey2", "key2", "value2_readonly"}, + {"NonExistingKey", "key4", nil}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - value, exists := roTree.Get(tt.key) - if exists != tt.exists || value != tt.expected { - t.Errorf("For key %s, expected %v (exists: %v), got %v (exists: %v)", tt.key, tt.expected, tt.exists, value, exists) + value := roTree.Get(tt.key) + if value != tt.expected { + t.Errorf("For key %s, expected %v, got %v", tt.key, tt.expected, value) } }) } @@ -168,7 +167,7 @@ func TestMakeEntrySafeFnVariants(t *testing.T) { // Modify the returned slice slice[0] = 999 // Verify original is unchanged - originalValue, _ := tree.Get("slice") + originalValue := tree.Get("slice") original := originalValue.([]int) if original[0] != 1 { t.Error("Original slice was modified") @@ -181,8 +180,8 @@ func TestMakeEntrySafeFnVariants(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { roTree := Wrap(tree, tt.makeEntrySafeFn) - value, exists := roTree.Get(tt.key) - if !exists { + value := roTree.Get(tt.key) + if value == nil { t.Fatal("Key not found") } tt.validate(t, value) @@ -200,8 +199,8 @@ func TestNilMakeEntrySafeFn(t *testing.T) { roTree := Wrap(tree, nil) // Test that we get back the original value - value, exists := roTree.Get("test") - if !exists { + value := roTree.Get("test") + if value == nil { t.Fatal("Key not found") } diff --git a/vendored/gno.land/p/nt/avl/v0/tree.gno b/vendored/gno.land/p/nt/avl/v0/tree.gno index c625fd7..f0bdffe 100644 --- a/vendored/gno.land/p/nt/avl/v0/tree.gno +++ b/vendored/gno.land/p/nt/avl/v0/tree.gno @@ -5,7 +5,7 @@ type ITree interface { Size() int Has(key string) bool - Get(key string) (value any, exists bool) + Get(key string) any GetByIndex(index int) (key string, value any) Iterate(start, end string, cb IterCbFn) bool ReverseIterate(start, end string, cb IterCbFn) bool @@ -47,10 +47,17 @@ func (tree *Tree) Has(key string) (has bool) { } // Get retrieves the value associated with the given key. -// It returns the value and a boolean indicating whether the key exists. -func (tree *Tree) Get(key string) (value any, exists bool) { - _, value, exists = tree.node.Get(key) - return +// It returns the value if the key exists, or nil if it doesn't. +// Note that a key stored with a nil value is indistinguishable +// from an absent key; use Has to check for existence. +// This allows for a simpler usage pattern with type assertions: +// +// if value, ok := tree.Get("key").(MyType); ok { +// // use value +// } +func (tree *Tree) Get(key string) any { + _, value, _ := tree.node.Get(key) + return value } // GetByIndex retrieves the key-value pair at the specified index in the tree. diff --git a/vendored/gno.land/p/nt/avl/v0/tree_test.gno b/vendored/gno.land/p/nt/avl/v0/tree_test.gno index a4e76e4..0e6df25 100644 --- a/vendored/gno.land/p/nt/avl/v0/tree_test.gno +++ b/vendored/gno.land/p/nt/avl/v0/tree_test.gno @@ -39,14 +39,14 @@ func TestTreeGet(t *testing.T) { tree := NewTree() tree.Set("key1", "value1") - value, exists := tree.Get("key1") - if !exists || value != "value1" { - t.Error("Expected Get to return value1 and true") + value := tree.Get("key1") + if value != "value1" { + t.Error("Expected Get to return value1") } - _, exists = tree.Get("key2") - if exists { - t.Error("Expected Get to return false for non-existent key") + value = tree.Get("key2") + if value != nil { + t.Error("Expected Get to return nil for non-existent key") } } diff --git a/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize.gno b/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize.gno index f5066fd..73ddeb1 100644 --- a/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize.gno +++ b/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize.gno @@ -1055,7 +1055,9 @@ func HTMLEscape(s string) string { // // Allowlist: // - http, https -// - mailto (rejected if contains ?body= or &body= — prefill phishing) +// - mailto (rejected if it carries any query: prefill phishing via +// body, subject, cc, etc. Both '?' and '&' are rejected; see +// linkSchemeAllowed for why '&' counts.) // - any URL WITHOUT a scheme — relative paths (`/path`, `./rel`, // `bare-path`), query-only (`?q=v`), fragment-only (`#anchor`). // A `:` appearing inside the URL (e.g. `/path:foo`, `?q=a:b`) is @@ -1622,8 +1624,14 @@ func linkSchemeAllowed(s string) bool { return true } if strings.HasPrefix(s, "mailto:") { - // Reject prefill phishing via ?body= or &body=. - if strings.Contains(s, "?body=") || strings.Contains(s, "&body=") { + // Reject any query: RFC 6068 headers (body, subject, cc, bcc, ...) + // prefill the composed message and are a phishing vector. '?' opens + // the header section (covering percent-encoded names like ?%62ody=). + // '&' is rejected because gnoweb's renderer decodes HTML character + // references ('?', '?', '?') back into '?' after this + // check, reconstituting a query. Percent-encoded '%3f' stays encoded + // and reads as a literal '?' in the address, so it's allowed. + if strings.ContainsAny(s, "?&") { return false } return true diff --git a/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize_test.gno b/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize_test.gno index bcbf92a..8cbfb10 100644 --- a/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize_test.gno +++ b/vendored/gno.land/p/nt/markdown/sanitize/v0/sanitize_test.gno @@ -333,10 +333,23 @@ func TestURL(t *testing.T) { {"https://example.com/x", "https://example.com/x"}, {"http://example.com", "http://example.com"}, {"mailto:a@b.com", "mailto:a@b.com"}, - {"mailto:a@b.com?body=phish", ""}, // prefill phishing rejected - {"//evil.com", ""}, // protocol-relative rejected - {"javascript:alert(1)", ""}, // bad scheme - {"/r/foo", "/r/foo"}, // relative + {"mailto:a@b.com?body=phish", ""}, // any query is a prefill-phishing vector + {"mailto:a@b.com?BODY=phish", ""}, // header name case is irrelevant + {"mailto:a@b.com?Body=phish", ""}, // mixed case + {"mailto:a@b.com?%62ody=phish", ""}, // percent-encoded header (%62 == b) + {"mailto:a@b.com?subject=hi&body=phish", ""}, // body as second param + {"mailto:a@b.com?subject=hi&BODY=phish", ""}, // mixed case second param + {"mailto:a@b.com?subject=hello", ""}, // subject alone still rejected + {"mailto:a@b.com?cc=x@y.com", ""}, // cc rejected + {"mailto:a@b.com?bcc=x@y.com", ""}, // bcc rejected + {"mailto:a@b.com?", ""}, // bare trailing query marker rejected + {"mailto:a@b.com?body=phish", ""}, // hex char-ref ? — renderer decodes to ?body= + {"mailto:a@b.com?body=phish", ""}, // decimal char-ref ? — same bypass + {"mailto:a@b.com?body=phish", ""}, // named char-ref ? — same bypass + {"mailto:a@b.com&body=phish", ""}, // bare & gateway rejected + {"//evil.com", ""}, // protocol-relative rejected + {"javascript:alert(1)", ""}, // bad scheme + {"/r/foo", "/r/foo"}, // relative {"./local", "./local"}, {"#section", "#section"}, // fragment-only {"", ""}, diff --git a/vendored/gno.land/p/nt/uassert/v0/uassert.gno b/vendored/gno.land/p/nt/uassert/v0/uassert.gno index 2b26d91..89381b8 100644 --- a/vendored/gno.land/p/nt/uassert/v0/uassert.gno +++ b/vendored/gno.land/p/nt/uassert/v0/uassert.gno @@ -2,6 +2,7 @@ package uassert import ( + "errors" "strconv" "strings" @@ -62,18 +63,13 @@ func False(t TestingT, value bool, msgs ...string) bool { return true } -// ErrorIs asserts the given error matches the target error +// ErrorIs asserts the given error matches the target error using errors.Is, +// which traverses the error chain looking for a match. func ErrorIs(t TestingT, err, target error, msgs ...string) bool { t.Helper() - if err == nil || target == nil { - return err == target - } - - // XXX: if errors.Is(err, target) return true - - if err.Error() != target.Error() { - return fail(t, msgs, "error mismatch, expected %s, got %s", target.Error(), err.Error()) + if !errors.Is(err, target) { + return fail(t, msgs, "error mismatch, expected %s, got %s", target, err) } return true diff --git a/vendored/gno.land/p/nt/urequire/v0/urequire.gno b/vendored/gno.land/p/nt/urequire/v0/urequire.gno index 9f94a28..3671e8d 100644 --- a/vendored/gno.land/p/nt/urequire/v0/urequire.gno +++ b/vendored/gno.land/p/nt/urequire/v0/urequire.gno @@ -6,6 +6,7 @@ import "gno.land/p/nt/uassert/v0" // type TestingT = uassert.TestingT // XXX: bug, should work +// NoError requires that a function returned no error (i.e. `nil`). func NoError(t uassert.TestingT, err error, msgs ...string) { t.Helper() if uassert.NoError(t, err, msgs...) { @@ -14,6 +15,7 @@ func NoError(t uassert.TestingT, err error, msgs ...string) { t.FailNow() } +// Error requires that a function returned an error (i.e. not `nil`). func Error(t uassert.TestingT, err error, msgs ...string) { t.Helper() if uassert.Error(t, err, msgs...) { @@ -22,6 +24,8 @@ func Error(t uassert.TestingT, err error, msgs ...string) { t.FailNow() } +// ErrorContains requires that a function returned an error (i.e. not `nil`) +// and that the error contains the specified substring. func ErrorContains(t uassert.TestingT, err error, contains string, msgs ...string) { t.Helper() if uassert.ErrorContains(t, err, contains, msgs...) { @@ -30,6 +34,7 @@ func ErrorContains(t uassert.TestingT, err error, contains string, msgs ...strin t.FailNow() } +// True requires that the specified value is true. func True(t uassert.TestingT, value bool, msgs ...string) { t.Helper() if uassert.True(t, value, msgs...) { @@ -38,6 +43,7 @@ func True(t uassert.TestingT, value bool, msgs ...string) { t.FailNow() } +// False requires that the specified value is false. func False(t uassert.TestingT, value bool, msgs ...string) { t.Helper() if uassert.False(t, value, msgs...) { @@ -46,6 +52,7 @@ func False(t uassert.TestingT, value bool, msgs ...string) { t.FailNow() } +// ErrorIs requires that the given error matches the target error. func ErrorIs(t uassert.TestingT, err, target error, msgs ...string) { t.Helper() if uassert.ErrorIs(t, err, target, msgs...) { @@ -67,6 +74,17 @@ func AbortsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs .. t.FailNow() } +// AbortsContains requires that the code inside the specified func aborts +// (panics when crossing another realm) and the abort message contains the specified substring. +// See uassert.AbortsWithMessage for `rlm` semantics. +func AbortsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string) { + t.Helper() + if uassert.AbortsContains(t, rlm, substr, f, msgs...) { + return + } + t.FailNow() +} + // NotAborts requires that the code inside the specified func does NOT abort // when crossing an execution boundary (e.g., VM call). // Use NotPanics for requiring the absence of local panics within the same realm. @@ -74,7 +92,7 @@ func AbortsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs .. // See uassert.AbortsWithMessage for `rlm` semantics. func NotAborts(t uassert.TestingT, rlm realm, f any, msgs ...string) { t.Helper() - if uassert.NotPanics(t, rlm, f, msgs...) { + if uassert.NotAborts(t, rlm, f, msgs...) { return } t.FailNow() @@ -92,6 +110,17 @@ func PanicsWithMessage(t uassert.TestingT, rlm realm, msg string, f any, msgs .. t.FailNow() } +// PanicsContains requires that the code inside the specified func panics +// locally within the same execution realm and the panic message contains the specified substring. +// See uassert.AbortsWithMessage for `rlm` semantics. +func PanicsContains(t uassert.TestingT, rlm realm, substr string, f any, msgs ...string) { + t.Helper() + if uassert.PanicsContains(t, rlm, substr, f, msgs...) { + return + } + t.FailNow() +} + // NotPanics requires that the code inside the specified func does NOT panic // locally within the same execution realm. // Use NotAborts for requiring the absence of panics that cross execution boundaries (aborts). @@ -104,6 +133,7 @@ func NotPanics(t uassert.TestingT, rlm realm, f any, msgs ...string) { t.FailNow() } +// Equal requires that two objects are equal. func Equal(t uassert.TestingT, expected, actual any, msgs ...string) { t.Helper() if uassert.Equal(t, expected, actual, msgs...) { @@ -112,6 +142,7 @@ func Equal(t uassert.TestingT, expected, actual any, msgs ...string) { t.FailNow() } +// NotEqual requires that two objects are not equal. func NotEqual(t uassert.TestingT, expected, actual any, msgs ...string) { t.Helper() if uassert.NotEqual(t, expected, actual, msgs...) { @@ -120,6 +151,8 @@ func NotEqual(t uassert.TestingT, expected, actual any, msgs ...string) { t.FailNow() } +// Empty requires that the specified object is empty +// (zero value, empty string/slice/map, or nil). func Empty(t uassert.TestingT, obj any, msgs ...string) { t.Helper() if uassert.Empty(t, obj, msgs...) { @@ -128,6 +161,7 @@ func Empty(t uassert.TestingT, obj any, msgs ...string) { t.FailNow() } +// NotEmpty requires that the specified object is not empty. func NotEmpty(t uassert.TestingT, obj any, msgs ...string) { t.Helper() if uassert.NotEmpty(t, obj, msgs...) { @@ -135,3 +169,39 @@ func NotEmpty(t uassert.TestingT, obj any, msgs ...string) { } t.FailNow() } + +// Nil requires that the value is nil. +func Nil(t uassert.TestingT, value any, msgs ...string) { + t.Helper() + if uassert.Nil(t, value, msgs...) { + return + } + t.FailNow() +} + +// NotNil requires that the value is not nil. +func NotNil(t uassert.TestingT, value any, msgs ...string) { + t.Helper() + if uassert.NotNil(t, value, msgs...) { + return + } + t.FailNow() +} + +// TypedNil requires that the value is a typed-nil (nil pointer) value. +func TypedNil(t uassert.TestingT, value any, msgs ...string) { + t.Helper() + if uassert.TypedNil(t, value, msgs...) { + return + } + t.FailNow() +} + +// NotTypedNil requires that the value is not a typed-nil (nil pointer) value. +func NotTypedNil(t uassert.TestingT, value any, msgs ...string) { + t.Helper() + if uassert.NotTypedNil(t, value, msgs...) { + return + } + t.FailNow() +} diff --git a/vendored/gno.land/p/onbloc/json/node_test.gno b/vendored/gno.land/p/onbloc/json/node_test.gno index 74f96c4..cc1cd24 100644 --- a/vendored/gno.land/p/onbloc/json/node_test.gno +++ b/vendored/gno.land/p/onbloc/json/node_test.gno @@ -1076,7 +1076,7 @@ func TestNode_ObjectEach(t *testing.T) { } } -func TestNode_ExampleMust(t *testing.T) { +func Example_TestNode_Must() { data := []byte(`{ "Image": { "Width": 800, @@ -1094,10 +1094,11 @@ func TestNode_ExampleMust(t *testing.T) { root := Must(Unmarshal(data)) if root.Size() != 1 { - t.Errorf("root.Size() must be 1. got: %v", root.Size()) + ufmt.Printf("root.Size() must be 1. got: %v\n", root.Size()) + return } - ufmt.Sprintf("Object has %d inheritors inside", root.Size()) + ufmt.Printf("Object has %d inheritors inside\n", root.Size()) // Output: // Object has 1 inheritors inside } diff --git a/vendored/gno.land/p/samcrew/piechart/README.md b/vendored/gno.land/p/samcrew/piechart/README.md index 22f28af..3c927dc 100644 --- a/vendored/gno.land/p/samcrew/piechart/README.md +++ b/vendored/gno.land/p/samcrew/piechart/README.md @@ -38,4 +38,4 @@ func Render(slices []PieSlice, title string) string ## Live Example - [/r/docs/charts:piechart](/r/docs/charts:piechart) -- [/r/samcrew/daodemo/custom_condition:members](/r/samcrew/daodemo/custom_condition:members) \ No newline at end of file +- [/r/samcrew/daodemo/custom_condition:members](/r/samcrew/daodemo/custom_condition:members) diff --git a/vendored/gno.land/r/demo/profile/profile.gno b/vendored/gno.land/r/demo/profile/profile.gno index c74852b..79f2572 100644 --- a/vendored/gno.land/r/demo/profile/profile.gno +++ b/vendored/gno.land/r/demo/profile/profile.gno @@ -118,7 +118,7 @@ func SetBoolField(cur realm, field string, value bool) bool { func GetStringField(addr address, field, def string) string { key := addr.String() + ":" + field - if value, ok := fields.Get(key); ok { + if value := fields.Get(key); value != nil { return value.(string) } @@ -127,7 +127,7 @@ func GetStringField(addr address, field, def string) string { func GetBoolField(addr address, field string, def bool) bool { key := addr.String() + ":" + field - if value, ok := fields.Get(key); ok { + if value := fields.Get(key); value != nil { return value.(bool) } @@ -136,7 +136,7 @@ func GetBoolField(addr address, field string, def bool) bool { func GetIntField(addr address, field string, def int) int { key := addr.String() + ":" + field - if value, ok := fields.Get(key); ok { + if value := fields.Get(key); value != nil { return value.(int) }