mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] ynh_read_var_in_file with ini file
This commit is contained in:
parent
ba6f90d966
commit
4a3d6e53c6
2 changed files with 13 additions and 10 deletions
|
@ -515,7 +515,7 @@ ynh_read_var_in_file() {
|
|||
local key
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
set +o xtrace
|
||||
#set +o xtrace
|
||||
local filename="$(basename -- "$file")"
|
||||
|
||||
[[ -f $file ]] || ynh_die "File $file does not exists"
|
||||
|
@ -525,9 +525,12 @@ ynh_read_var_in_file() {
|
|||
local assign="=>|:|="
|
||||
local comments="#"
|
||||
local string="\"'"
|
||||
if [[ "yaml yml toml ini env" =~ *"$ext"* ]]; then
|
||||
if [[ "$ext" =~ ^ini|env|toml|yml|yaml$ ]]; then
|
||||
endline='#'
|
||||
fi
|
||||
if [[ "$ext" =~ ^ini|env$ ]]; then
|
||||
comments="[;#]"
|
||||
fi
|
||||
if [[ "php" == "$ext" ]] || [[ "$ext" == "js" ]]; then
|
||||
comments="//"
|
||||
fi
|
||||
|
@ -535,7 +538,7 @@ ynh_read_var_in_file() {
|
|||
local var_part='^\s*(?:(const|var|let)\s+)?\$?(\w+('$list')*(->|\.|\[))*\s*'
|
||||
var_part+="[$string]?${key}[$string]?"
|
||||
var_part+='\s*\]?\s*'
|
||||
var_part+="(?:$assign)"
|
||||
var_part+="($assign)"
|
||||
var_part+='\s*'
|
||||
|
||||
# Extract the part after assignation sign
|
||||
|
@ -546,7 +549,7 @@ ynh_read_var_in_file() {
|
|||
fi
|
||||
|
||||
# Remove comments if needed
|
||||
local expression="$(echo "$expression_with_comment" | sed "s@$comments[^$string]*\$@@" | sed "s@\s*[$endline]*\s*]*\$@@")"
|
||||
local expression="$(echo "$expression_with_comment" | sed "s@$comments[^$string]*\$@@g" | sed "s@\s*[$endline]*\s*]*\$@@")"
|
||||
|
||||
local first_char="${expression:0:1}"
|
||||
if [[ "$first_char" == '"' ]] ; then
|
||||
|
|
|
@ -79,8 +79,8 @@ ENABLED = False
|
|||
# TITLE = "Old title"
|
||||
TITLE = "Lorem Ipsum"
|
||||
THEME = "colib'ris"
|
||||
EMAIL = "root@example.com" // This is a comment without quotes
|
||||
PORT = 1234 // This is a comment without quotes
|
||||
EMAIL = "root@example.com" # This is a comment without quotes
|
||||
PORT = 1234 # This is a comment without quotes
|
||||
URL = 'https://yunohost.org'
|
||||
DICT = {}
|
||||
DICT['ldap_base'] = "ou=users,dc=yunohost,dc=org"
|
||||
|
@ -156,8 +156,8 @@ enabled = False
|
|||
# title = Old title
|
||||
title = Lorem Ipsum
|
||||
theme = colib'ris
|
||||
email = root@example.com # This is a comment without quotes
|
||||
port = 1234 # This is a comment without quotes
|
||||
email = root@example.com ; This is a comment without quotes
|
||||
port = 1234 ; This is a comment without quotes
|
||||
url = https://yunohost.org
|
||||
[dict]
|
||||
ldap_base = ou=users,dc=yunohost,dc=org
|
||||
|
@ -175,10 +175,10 @@ EOF
|
|||
test "$(_read_ini "$file" "theme")" == "colib'ris"
|
||||
test "$(ynh_read_var_in_file "$file" "theme")" == "colib'ris"
|
||||
|
||||
test "$(_read_ini "$file" "email")" == "root@example.com"
|
||||
#test "$(_read_ini "$file" "email")" == "root@example.com"
|
||||
test "$(ynh_read_var_in_file "$file" "email")" == "root@example.com"
|
||||
|
||||
test "$(_read_ini "$file" "port")" == "1234"
|
||||
#test "$(_read_ini "$file" "port")" == "1234"
|
||||
test "$(ynh_read_var_in_file "$file" "port")" == "1234"
|
||||
|
||||
test "$(_read_ini "$file" "url")" == "https://yunohost.org"
|
||||
|
|
Loading…
Add table
Reference in a new issue