CodeSampleX

Beispiel

golang.org/x/net v0.0.0-20180724234803-3673e40ba225: html.ParseFragment

Verifiziertes Beispiel für golang golang.org/x/net v0.0.0-20180724234803-3673e40ba225: html.ParseFragment. Der Vertrag lief auf go 1.26 · linux debian/x64 …

sha256:af6b6efd44d9ee4f7e73db903974f3a3489cc020cc76bda91895a34ade8b90a2

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-10-17

Fall

HOW
Ziel
verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225
Pakete
Symbole
  • golang.org/x/net/html.ParseFragment
Erstellt
2026-10-17T20:22:09Z

Contract

  1. html.ParseFragment with nil context parses a fragment into a root html element containing head and body
  2. html.ParseFragment with a body element context parses child elements directly without outer html/body wrappers
  3. html.ParseFragment with a table element context wraps tr elements inside an implicit tbody element
  4. html.ParseFragment with a select element context parses option elements and preserves their attributes

Dateien

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Quellartefakt herunterladen (tar.gz)

Quelltext

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225
Demonstrate these symbols/APIs:
  - golang.org/x/net/html.ParseFragment

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:607ab9340b0f02210af40088d7da392d19ab82aa01a413d77c7f8f39055bea31","contract":["html.ParseFragment with nil context parses a fragment into a root html element containing head and body","html.ParseFragment with a body element context parses child elements directly without outer html/body wrappers","html.ParseFragment with a table element context wraps tr elements inside an implicit tbody element","html.ParseFragment with a select element context parses option elements and preserves their attributes"],"goal":"verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225","kind":"HOW","packages":["pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225"],"schemaVersion":1,"symbols":["golang.org/x/net/html.ParseFragment"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225","symbols":["golang.org/x/net/html.ParseFragment"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.21

require golang.org/x/net v0.0.0-20180724234803-3673e40ba225
go.sum
golang.org/x/net v0.0.0-20180724234803-3673e40ba225 h1:kNX+jCowfMYzvlSvJu5pQWEmyWFrBXJ3PBy10xKMXK8=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/net/html.ParseFragment in pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/net@v0.0.0-20180724234803-3673e40ba225"
  ],
  "symbols": [
    "golang.org/x/net/html.ParseFragment"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	"golang.org/x/net/html"
	"golang.org/x/net/html/atom"
)

func fail(msg string, args ...any) {
	fmt.Fprintf(os.Stderr, msg+"\n", args...)
	os.Exit(1)
}

func main() {
	// 1. ParseFragment with nil context parses into a root html element containing head and body.
	nodesNil, err := html.ParseFragment(strings.NewReader("<p>hello <b>world</b></p>"), nil)
	if err != nil {
		fail("ParseFragment with nil context failed: %v", err)
	}
	if len(nodesNil) != 1 || nodesNil[0].Type != html.ElementNode || nodesNil[0].Data != "html" {
		fail("expected single root html element node for nil context, got %v", nodesNil)
	}
	rootHTML := nodesNil[0]
	if rootHTML.FirstChild == nil || rootHTML.FirstChild.Data != "head" {
		fail("expected first child of html root to be head")
	}
	if rootHTML.LastChild == nil || rootHTML.LastChild.Data != "body" {
		fail("expected last child of html root to be body")
	}
	bodyChild := rootHTML.LastChild.FirstChild
	if bodyChild == nil || bodyChild.Type != html.ElementNode || bodyChild.Data != "p" {
		fail("expected p element inside body, got %v", bodyChild)
	}

	// 2. ParseFragment with a body element context parses child elements directly without html/body wrappers.
	bodyCtx := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Body,
		Data:     "body",
	}
	nodesBody, err := html.ParseFragment(strings.NewReader("<div>alpha</div><span>beta</span>"), bodyCtx)
	if err != nil {
		fail("ParseFragment with body context failed: %v", err)
	}
	if len(nodesBody) != 2 {
		fail("expected 2 nodes with body context, got %d", len(nodesBody))
	}
	if nodesBody[0].Type != html.ElementNode || nodesBody[0].Data != "div" || nodesBody[0].FirstChild == nil || nodesBody[0].FirstChild.Data != "alpha" {
		fail("unexpected first node in body context: %+v", nodesBody[0])
	}
	if nodesBody[1].Type != html.ElementNode || nodesBody[1].Data != "span" || nodesBody[1].FirstChild == nil || nodesBody[1].FirstChild.Data != "beta" {
		fail("unexpected second node in body context: %+v", nodesBody[1])
	}

	// 3. ParseFragment with a table element context wraps tr elements inside an implicit tbody element.
	tableCtx := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Table,
		Data:     "table",
	}
	nodesTable, err := html.ParseFragment(strings.NewReader("<tr><td>cell1</td><td>cell2</td></tr>"), tableCtx)
	if err != nil {
		fail("ParseFragment with table context failed: %v", err)
	}
	if len(nodesTable) != 1 || nodesTable[0].Type != html.ElementNode || nodesTable[0].Data != "tbody" {
		fail("expected single implicit tbody element in table context, got %v", nodesTable)
	}
	trNode := nodesTable[0].FirstChild
	if trNode == nil || trNode.Type != html.ElementNode || trNode.Data != "tr" {
		fail("expected tr element inside tbody, got %v", trNode)
	}
	if trNode.FirstChild == nil || trNode.FirstChild.Data != "td" || trNode.LastChild == nil || trNode.LastChild.Data != "td" || trNode.FirstChild == trNode.LastChild {
		fail("expected two td children inside tr")
	}

	// 4. ParseFragment with a select element context parses option elements and preserves their attributes.
	selectCtx := &html.Node{
		Type:     html.ElementNode,
		DataAtom: atom.Select,
		Data:     "select",
	}
	nodesSelect, err := html.ParseFragment(strings.NewReader(`<option value="one" selected>First</option><option value="two">Second</option>`), selectCtx)
	if err != nil {
		fail("ParseFragment with select context failed: %v", err)
	}
	if len(nodesSelect) != 2 {
		fail("expected 2 option nodes in select context, got %d", len(nodesSelect))
	}
	if nodesSelect[0].Data != "option" || len(nodesSelect[0].Attr) != 2 || nodesSelect[0].Attr[0].Key != "value" || nodesSelect[0].Attr[0].Val != "one" {
		fail("unexpected first option node or attributes: %+v", nodesSelect[0])
	}
	if nodesSelect[0].FirstChild == nil || nodesSelect[0].FirstChild.Type != html.TextNode || nodesSelect[0].FirstChild.Data != "First" {
		fail("unexpected first option text child")
	}
	if nodesSelect[1].Data != "option" || len(nodesSelect[1].Attr) != 1 || nodesSelect[1].Attr[0].Key != "value" || nodesSelect[1].Attr[0].Val != "two" {
		fail("unexpected second option node or attributes: %+v", nodesSelect[1])
	}
}

Ursprungs-Seeder

anonym