mirror of
https://github.com/containers/podman.git
synced 2025-06-21 01:19:15 +08:00
Merge pull request #3622 from QiWang19/checkurl
fix import not ignoring url path
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/shared/parse"
|
"github.com/containers/libpod/cmd/podman/shared/parse"
|
||||||
"github.com/containers/libpod/pkg/adapter"
|
"github.com/containers/libpod/pkg/adapter"
|
||||||
|
multierror "github.com/hashicorp/go-multierror"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@ -69,8 +70,11 @@ func importCmd(c *cliconfig.ImportValues) error {
|
|||||||
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
|
return errors.Errorf("too many arguments. Usage TARBALL [REFERENCE]")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := parse.ValidateFileName(source); err != nil {
|
errFileName := parse.ValidateFileName(source)
|
||||||
return err
|
errURL := parse.ValidURL(source)
|
||||||
|
|
||||||
|
if errFileName != nil && errURL != nil {
|
||||||
|
return multierror.Append(errFileName, errURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
quiet := c.Quiet
|
quiet := c.Quiet
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -162,3 +163,12 @@ func ValidateFileName(filename string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidURL checks a string urlStr is a url or not
|
||||||
|
func ValidURL(urlStr string) error {
|
||||||
|
_, err := url.ParseRequestURI(urlStr)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "invalid url path: %q", urlStr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user