MCPcopy Create free account
hub / github.com/cli/cli / checkAltStaysInside

Function checkAltStaysInside

internal/attachments/userasset.go:209–215  ·  view source on GitHub ↗

checkAltStaysInside renders the image this asset will produce and parses it back, so alt text that escapeAlt failed to neutralize is refused before the upload rather than discovered after it. An upload cannot be undone, which is why the check runs at validation. The URL is a stand-in, since the rea

(a *imageAsset)

Source from the content-addressed store, hash-verified

207// The URL is a stand-in, since the real one does not exist until the asset has
208// uploaded. Only the alt text varies, so a stand-in proves the same thing.
209func checkAltStaysInside(a *imageAsset) error {
210 const probeURL = "https://example.invalid/probe"
211 if !isSingleImage(a.markdown(probeURL), probeURL) {
212 return fmt.Errorf("%s: alt text cannot be rendered safely", a.path)
213 }
214 return nil
215}

Callers 1

newImageAssetFunction · 0.85

Calls 3

isSingleImageFunction · 0.85
markdownMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected