-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(validation): Add support for properties files (#52)
* Add PropValidator which impliments Validator interface to prase byte array of properties Signed-off-by: gokulav137 <[email protected]> * Add valid and invalid scenarios for testing PropValidator Signed-off-by: gokulav137 <[email protected]> * Add PropFiletype to represent properties file and mapped it to PropValidator Signed-off-by: gokulav137 <[email protected]> * Add good and bad .properties files to test/fixtures Signed-off-by: gokulav137 <[email protected]> * Fix typo in test name: Properites -> Properties Signed-off-by: gokulav137 <[email protected]> * Add magiconair/properties to go.mod Signed-off-by: gokulav137 <[email protected]> * Add Properties to supported types in README Signed-off-by: gokulav137 <[email protected]> * Fix padding issue for multiline validation errors Signed-off-by: gokulav137 <[email protected]> * Add test case to cover multiline error padding case Signed-off-by: gokulav137 <[email protected]> * Add doc comment for padErrorString method Signed-off-by: gokulav137 <[email protected]> --------- Signed-off-by: gokulav137 <[email protected]>
- Loading branch information
1 parent
99d67a3
commit db9e556
Showing
10 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package validator | ||
|
||
import ( | ||
"github.com/magiconair/properties" | ||
) | ||
|
||
type PropValidator struct{} | ||
|
||
// Validate implements the Validator interface by attempting to | ||
// parse a byte array of properties | ||
func (pv PropValidator) Validate(b []byte) (bool, error) { | ||
l := &properties.Loader{Encoding: properties.UTF8} | ||
_, err := l.LoadBytes(b) | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# You are reading a comment in ".properties" file. | ||
! The exclamation mark can also be used for comments. | ||
# Lines with "properties" contain a key and a value separated by a delimiting character. | ||
# There are 3 delimiting characters: '=' (equal), ':' (colon) and whitespace (space, \t and \f). | ||
website = https://en.wikipedia.org/ | ||
language : English | ||
topic .properties files | ||
# A word on a line will just create a key with no value. | ||
empty | ||
# White space that appears between the key, the value and the delimiter is ignored. | ||
# This means that the following are equivalent (other than for readability). | ||
hello=hello | ||
hello = hello | ||
# Keys with the same name will be overwritten by the key that is the furthest in a file. | ||
# For example the final value for "duplicateKey" will be "second". | ||
duplicateKey = first | ||
duplicateKey = second | ||
# To use the delimiter characters inside a key, you need to escape them with a \. | ||
# However, there is no need to do this in the value. | ||
delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ " | ||
# Adding a \ at the end of a line means that the value continues to the next line. | ||
multiline = This line \ | ||
continues | ||
# If you want your value to include a \, it should be escaped by another \. | ||
path = c:\\wiki\\templates | ||
# This means that if the number of \ at the end of the line is even, the next line is not included in the value. | ||
# In the following example, the value for "evenKey" is "This is on one line\". | ||
evenKey = This is on one line\\ | ||
# This line is a normal comment and is not included in the value for "evenKey" | ||
# If the number of \ is odd, then the next line is included in the value. | ||
# In the following example, the value for "oddKey" is "This is line one and\#This is line two". | ||
oddKey = This is line one and\\\ | ||
# This is line two | ||
# White space characters are removed before each line. | ||
# Make sure to add your spaces before your \ if you need them on the next line. | ||
# In the following example, the value for "welcome" is "Welcome to Wikipedia!". | ||
welcome = Welcome to \ | ||
Wikipedia! | ||
# If you need to add newlines and carriage returns, they need to be escaped using \n and \r respectively. | ||
# You can also optionally escape tabs with \t for readability purposes. | ||
valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t. | ||
# You can also use Unicode escape characters (maximum of four hexadecimal digits). | ||
# In the following example, the value for "encodedHelloInJapanese" is "こんにちは". | ||
encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f | ||
# But with more modern file encodings like UTF-8, you can directly use supported characters. | ||
helloInJapanese = こんにちは |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# You are reading a comment in ".properties" file. | ||
! The exclamation mark can also be used for comments. | ||
# Lines with "properties" contain a key and a value separated by a delimiting character. | ||
# There are 3 delimiting characters: '=' (equal), ':' (colon) and whitespace (space, \t and \f). | ||
website = https://en.wikipedia.org/ | ||
language : English | ||
topic .properties files | ||
# A word on a line will just create a key with no value. | ||
empty | ||
# White space that appears between the key, the value and the delimiter is ignored. | ||
# This means that the following are equivalent (other than for readability). | ||
hello=hello | ||
hello = hello | ||
# Keys with the same name will be overwritten by the key that is the furthest in a file. | ||
# For example the final value for "duplicateKey" will be "second". | ||
duplicateKey = first | ||
duplicateKey = second | ||
# To use the delimiter characters inside a key, you need to escape them with a \. | ||
# However, there is no need to do this in the value. | ||
delimiterCharacters\:\=\ = This is the value for the key "delimiterCharacters\:\=\ " | ||
# Adding a \ at the end of a line means that the value continues to the next line. | ||
multiline = This line \ | ||
continues | ||
# If you want your value to include a \, it should be escaped by another \. | ||
path = c:\\wiki\\templates | ||
# This means that if the number of \ at the end of the line is even, the next line is not included in the value. | ||
# In the following example, the value for "evenKey" is "This is on one line\". | ||
evenKey = This is on one line\\ | ||
# This line is a normal comment and is not included in the value for "evenKey" | ||
# If the number of \ is odd, then the next line is included in the value. | ||
# In the following example, the value for "oddKey" is "This is line one and\#This is line two". | ||
oddKey = This is line one and\\\ | ||
# This is line two | ||
# White space characters are removed before each line. | ||
# Make sure to add your spaces before your \ if you need them on the next line. | ||
# In the following example, the value for "welcome" is "Welcome to Wikipedia!". | ||
welcome = Welcome to \ | ||
Wikipedia! | ||
# If you need to add newlines and carriage returns, they need to be escaped using \n and \r respectively. | ||
# You can also optionally escape tabs with \t for readability purposes. | ||
valueWithEscapes = This is a newline\n and a carriage return\r and a tab\t. | ||
# You can also use Unicode escape characters (maximum of four hexadecimal digits). | ||
# In the following example, the value for "encodedHelloInJapanese" is "こんにちは". | ||
encodedHelloInJapanese = \u3053\u3093\u306b\u3061\u306f | ||
# But with more modern file encodings like UTF-8, you can directly use supported characters. | ||
helloInJapanese = こんにちは | ||
# Circular Dependency | ||
key = ${key} |