Files
w3cjandClaude Opus 5.5 fb19879aaa fix(msg): one rule for which characters reach the terminal
msg.Safe is the one owner: a graphic character in any script is safe;
controls, bidi controls, format characters, variation selectors, private
use and the invisible fillers are not. Printable and OneLine drop what
Safe refuses, agent save's diff escapes it, and forbidigo bans
unicode.IsGraphic, IsPrint, IsControl and Bidi_Control outside
internal/msg.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-08 10:04:59 -07:00

48 lines
1.7 KiB
Go

package settings
import (
"net/url"
"strings"
"unicode"
"github.com/devvmhq/devvm/internal/msg"
"github.com/devvmhq/devvm/internal/paths"
)
// KeyUbuntuMirror is config.toml's Ubuntu mirror, which base's first build
// tries before Ubuntu's own archive.
const KeyUbuntuMirror = "ubuntu-mirror"
// UbuntuMirror is config.toml's ubuntu-mirror, "" when it sets none: the
// address of a mirror of Ubuntu's archive for this machine's architecture,
// which base's first build gets its packages from first. A mirror only
// serves files: apt still checks every package against Ubuntu's archive
// key, so it can't give base a package Ubuntu didn't publish; it can
// serve older lists, which apt accepts.
func UbuntuMirror(d paths.Dirs) (string, error) {
cf, err := decodeConfig(d.ConfigFile())
if err != nil {
return "", err
}
return cf.UbuntuMirror.v, nil
}
type ubuntuMirrorKind struct{}
func (ubuntuMirrorKind) parse(v any) (string, error) { return checked(text(v))(checkUbuntuMirror) }
// checkUbuntuMirror refuses a mirror that isn't an http:// or https://
// address with a host, or that holds a user, a query, a fragment, a space
// or a control character: it goes onto a line of the build's own list of
// mirrors, which apt reads.
func checkUbuntuMirror(s string) error {
u, err := url.Parse(s)
bad := err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" ||
u.User != nil || u.RawQuery != "" || u.Fragment != "" || u.Opaque != "" ||
strings.ContainsFunc(s, func(r rune) bool { return unicode.IsSpace(r) || unicode.IsControl(r) }) //nolint:forbidigo // a line of apt's list, not the terminal
if bad {
return msg.UbuntuMirrorInvalid(KeyUbuntuMirror)
}
return nil
}