SelectFirst returns nil if the selector doesn't match any element (see nodes.go:15-19 — First() returns nil for empty Nodes). If the archive.ph page layout changes or loads differently, calling .Type() on a nil Node will cause a nil pointer panic.
input:=doc.SelectFirst("input[name='url']")ifinput==nil{_=doc.Close()returnnil,fmt.Errorf("failed to find URL input field")}err=input.Type(u.String())
**Parent:** #1
## Description
In `sites/archive/archive.go:107-114`:
```go
err = doc.SelectFirst("input[name='url']").Type(u.String())
```
`SelectFirst` returns `nil` if the selector doesn't match any element (see `nodes.go:15-19` — `First()` returns `nil` for empty `Nodes`). If the archive.ph page layout changes or loads differently, calling `.Type()` on a nil `Node` will cause a nil pointer panic.
Same issue on line 114:
```go
err = doc.SelectFirst("form#submiturl input[type=\"submit\"]").Click()
```
## Fix
Check for nil before calling methods:
```go
input := doc.SelectFirst("input[name='url']")
if input == nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to find URL input field")
}
err = input.Type(u.String())
```
Starting work on this as part of PR 2 (also includes #11). Will add nil guards for SelectFirst() results in archive.go and nil check for resp in document.go:Refresh().
Starting work on this as part of PR 2 (also includes #11). Will add nil guards for `SelectFirst()` results in `archive.go` and nil check for `resp` in `document.go:Refresh()`.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Parent: #1
Description
In
sites/archive/archive.go:107-114:SelectFirstreturnsnilif the selector doesn't match any element (seenodes.go:15-19—First()returnsnilfor emptyNodes). If the archive.ph page layout changes or loads differently, calling.Type()on a nilNodewill cause a nil pointer panic.Same issue on line 114:
Fix
Check for nil before calling methods:
Starting work on this as part of PR 2 (also includes #11). Will add nil guards for
SelectFirst()results inarchive.goand nil check forrespindocument.go:Refresh().Work finished. PR: #33
Added nil guards for
SelectFirst()results inarchive.gobefore calling.Type()and.Click().