clean

package
v0.0.0-...-c8acfb9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package clean provides validation, sanitation, and normalization of input values.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const (
	ClipShortType = 8
	ClipType      = 64
)
View Source
const (
	EnOr       = "or"
	EnAnd      = "and"
	EnWith     = "with"
	EnIn       = "in"
	EnAt       = "at"
	Empty      = ""
	Space      = " "
	Or         = "|"
	And        = "&"
	Plus       = "+"
	SpacedPlus = Space + Plus + Space
)
View Source
const MaxLength = 4096

Variables

View Source
var EmailRegexp = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")

Functions

func ASCII

func ASCII(s string) string

ASCII removes all non-ascii characters from a string and returns it.

func Altitude

func Altitude(a float64) int

Altitude returns the altitude within a maximum range as an integer, or 0 if it is invalid.

func Attr

func Attr(s string) string

Attr returns the sanitized attributes.

func Auth

func Auth(s string) string

Auth returns the sanitized authentication identifier trimmed to a maximum length of 255 characters.

func Clip

func Clip(s string, maxLen int) string

Clip shortens a string to the given number of characters, and removes all leading and trailing white space.

func Codec

func Codec(s string) string

Codec removes non-alphanumeric characters from a string and returns it.

func Color

func Color(s string) string

Color sanitizes HTML color codes and returns them in lowercase if they are valid, or an empty string otherwise.

func Duration

func Duration(s string) string

Duration removes non-duration characters from a string and returns the result.

func Email

func Email(s string) string

Email returns the sanitized email with trimmed whitespace and in lowercase.

func Error

func Error(err error) string

Error sanitizes an error message so that it can be safely logged or displayed.

func FileName

func FileName(s string) string

FileName removes invalid character from a filename string.

func GPSBounds

func GPSBounds(bounds string) (latN, lngE, latS, lngW float32, err error)

GPSBounds parses the GPS bounds (Lat N, Lng E, Lat S, Lng W) and returns the coordinates if any.

func GPSLatRange

func GPSLatRange(lat float64, km float64) (latN, latS float32, err error)

GPSLatRange returns a range based on the specified latitude and distance in km, or an error otherwise.

func GPSLngRange

func GPSLngRange(lng float64, km float64) (lngE, lngW float32, err error)

GPSLngRange returns a range based on the specified longitude and distance in km, or an error otherwise.

func Handle

func Handle(s string) string

Handle returns the sanitized username with trimmed whitespace and in lowercase.

func Header(s string) string

Header sanitizes a string for use in request or response headers.

func Hex

func Hex(s string) string

Hex removes invalid character from a hex string and makes it lowercase.

func ID

func ID(s string) string

ID sanitizes identifier tokens, for example, a session ID, a UUID, or some other string ID.

func IdUint

func IdUint(s string) uint

IdUint converts the string converted to an unsigned integer and 0 if the string is invalid.

func Log

func Log(s string) string

Log sanitizes strings created from user input in response to the log4j debacle.

func LogLower

func LogLower(s string) string

LogLower sanitizes strings created from user input and converts them to lowercase.

func LogQuote

func LogQuote(s string) string

LogQuote sanitizes a string and puts it in single quotes for logging.

func Name

func Name(name string) string

Name sanitizes a name string.

func NameCapitalized

func NameCapitalized(name string) string

NameCapitalized sanitizes and capitalizes a name.

func Numeric

func Numeric(s string) string

Numeric removes non-numeric characters from a string and returns the result.

func Orientation

func Orientation(val int) int

Orientation returns the Exif orientation value within a valid range or 0 if it is invalid.

func Passcode

func Passcode(s string) string

Passcode sanitizes a passcode and returns it in lowercase with all whitespace removed.

func Password

func Password(s string) string

Password returns the password string with all leading and trailing white space removed.

func Path

func Path(s string) string

Path removes invalid character from a path string.

func Role

func Role(s string) string

Role returns the sanitized role with trimmed whitespace and in lowercase.

func Scope

func Scope(s string) string

Scope sanitizes a string that contains authentication scope identifiers.

func SearchQuery

func SearchQuery(s string) string

SearchQuery replaces search operator with default symbols.

func SearchString

func SearchString(s string) string

SearchString replaces search operator with default symbols.

func ShareToken

func ShareToken(s string) string

ShareToken returns the sanitized link share token with a length of up to 160 characters.

func ShortType

func ShortType(s string) string

ShortType omits invalid runes, ensures a maximum length of 8 characters, and returns the result.

func ShortTypeLower

func ShortTypeLower(s string) string

ShortTypeLower converts a short type string to lowercase, omits invalid runes, and shortens it if needed.

func ShortTypeLowerUnderscore

func ShortTypeLowerUnderscore(s string) string

ShortTypeLowerUnderscore converts a string to a short lowercase type string and replaces spaces with underscores.

func SqlSpecial

func SqlSpecial(b byte) (special bool, omit bool)

SqlSpecial checks if the byte must be escaped/omitted in SQL.

func SqlString

func SqlString(s string) string

SqlString escapes a string for use in an SQL query.

func State

func State(s, countryCode string) string

State returns the full, normalized state name.

func Token

func Token(s string) string

Token returns the sanitized token string with a length of up to 4096 characters.

func Type

func Type(s string) string

Type omits invalid runes, ensures a maximum length of 32 characters, and returns the result.

func TypeLower

func TypeLower(s string) string

TypeLower converts a type string to lowercase, omits invalid runes, and shortens it if needed.

func TypeLowerUnderscore

func TypeLowerUnderscore(s string) string

TypeLowerUnderscore converts a string to a lowercase type string and replaces spaces with underscores.

func UID

func UID(s string) string

UID sanitizes unique identifier strings and returns them in lowercase.

func Unicode

func Unicode(s string) string

Unicode returns a string a valid unicode.

func Uri

func Uri(s string) string

Uri removes invalid character from an uri string.

func UrlToken

func UrlToken(s string) string

UrlToken returns the sanitized URL token with a length of up to 42 characters.

func UserPath

func UserPath(dir string) string

UserPath sanitizes and normalizes a user provided path, so it can be used.

func Username

func Username(s string) string

Username returns the sanitized distinguished name (Username) with trimmed whitespace and in lowercase.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL