From f3cbd539dc59c97169f7f642df4e8ba9565e73f8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 7 Jun 2020 14:57:57 -0400 Subject: [PATCH 1/9] cmd.py AdapterOeis topic parse Replace all non (alphanumeric, '-') chars with Spaces --- lib/adapter/cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/adapter/cmd.py b/lib/adapter/cmd.py index 7680998..7ecbdf3 100644 --- a/lib/adapter/cmd.py +++ b/lib/adapter/cmd.py @@ -130,10 +130,10 @@ class AdapterOeis(CommandAdapter): cmd[0] = _get_abspath(cmd[0]) # cut oeis/ off - # Replace all non (numeric, '-') chars with Spaces to delimit args to oeis.sh + # Replace all non (alphanumeric, '-') chars with Spaces to delimit args to oeis.sh if topic.startswith("oeis/"): topic = topic[5:] - topic = re.sub('[^0-9-]', ' ', topic) + topic = re.sub('[^a-zA-Z0-9-]', ' ', topic) return cmd + [topic] From 105bf883bdc771dab99536cb000a865afa9d24c4 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Jun 2020 08:10:29 -0400 Subject: [PATCH 2/9] Made --t--t--s and invalid string --- share/adapters/chmod.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index 233cb4c..7f320b2 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -72,12 +72,19 @@ chmod_calc(){ [[ ${1:$i:1} == 'w' ]] && W+=('X') || W+=(' ') [[ ${1:$((i++)):1} == 'w' ]] && let num++ num=$(( num << 1 )) - [[ 'stx' =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') - [[ 'stx' =~ ${1:$((i++)):1} ]] && let num++ + if [ $i -lt 6 ] + then + [[ "tT" =~ ${1:$i:1} ]] && return 1 + [[ "sx" =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') + [[ "sx" =~ ${1:$((i++)):1} ]] && let num++ + else + [[ "sS" =~ ${1:$i:1} ]] && return 1 + [[ "tx" =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') + [[ "tx" =~ ${1:$((i++)):1} ]] && let num++ + fi p_n+="$num" done else - printf "Invalid permissions string: $1" return 1 fi # Print Final results table @@ -95,3 +102,4 @@ Sticky bit [$sticky]\tExecute [${X[0]}]\tExecute [${X[1]}]\tExecute [${X[2]}] } chmod_calc $@ +[ $? -ne 0 ] && printf "Invalid permissions string: $@\n" From 657d4b6f480106830264f4c55bee20ca6541f29d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Jun 2020 08:35:26 -0400 Subject: [PATCH 3/9] 1-4 digit numbers are now valid. Changed var names --- share/adapters/chmod.sh | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index 7f320b2..ccf41ad 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -16,15 +16,15 @@ chmod_calc(){ setuid=' ' setgid=' ' sticky=' ' - # If permission number is given calc string - if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 2 && ${#1} -le 4 ]] + # If permission number is given -> calc string + if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 1 && ${#1} -le 4 ]] then - p_n=$1 - for (( i=0; i<${#1}; i++ )) + p_n=$(printf "%04s\n" "$1" | tr ' ' '0') + for (( i=0; i<${#p_n}; i++ )) do - num=$(echo "obase=2;${1:$i:1}" | bc | xargs printf '%03d') - # If 4 digit input, process specials - if [[ ${#1} -eq 4 && $i -eq 0 ]] + num=$(echo "obase=2;${p_n:$i:1}" | bc | xargs printf '%03d') + # If 4 digit input -> process specials + if [[ ${#p_n} -eq 4 && $i -eq 0 ]] then [ ${num:0:1} -eq 1 ] && setuid='X' || setuid=' ' [ ${num:1:1} -eq 1 ] && setgid='X' || setgid=' ' @@ -52,8 +52,8 @@ chmod_calc(){ [ ${num:2:1} -eq 1 ] && X+=('X') || X+=(' ') fi done - # If permission string is given calc number - elif [[ ${#1} -le 9 && $(( ${#1} % 3 )) -eq 0 && $1 =~ ^[r,s,S,t,T,w,x,-]+$ ]] + # If permission string is given -> calc number + elif [[ ${#1} -eq 9 && $1 =~ ^[r,s,S,t,T,w,x,-]+$ ]] then p_s=$1 num=0 @@ -63,24 +63,24 @@ chmod_calc(){ [[ 'tT' =~ ${p_s:8:1} ]] && sticky='X' && num=$((num+1)) [ ${num} -gt 0 ] && p_n+="$num" # Calculate rest of p_n number while populating arrays for table - for (( i=0; i<${#1}; i+=0 )) + for (( i=0; i<${#p_s}; i+=0 )) do num=0 - [[ ${1:$i:1} == 'r' ]] && R+=('X') || R+=(' ') - [[ ${1:$((i++)):1} == 'r' ]] && let num++ + [[ ${p_s:$i:1} == 'r' ]] && R+=('X') || R+=(' ') + [[ ${p_s:$((i++)):1} == 'r' ]] && let num++ num=$(( num << 1 )) - [[ ${1:$i:1} == 'w' ]] && W+=('X') || W+=(' ') - [[ ${1:$((i++)):1} == 'w' ]] && let num++ + [[ ${p_s:$i:1} == 'w' ]] && W+=('X') || W+=(' ') + [[ ${p_s:$((i++)):1} == 'w' ]] && let num++ num=$(( num << 1 )) if [ $i -lt 6 ] then - [[ "tT" =~ ${1:$i:1} ]] && return 1 - [[ "sx" =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') - [[ "sx" =~ ${1:$((i++)):1} ]] && let num++ + [[ "tT" =~ ${p_s:$i:1} ]] && return 1 + [[ "sx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') + [[ "sx" =~ ${p_s:$((i++)):1} ]] && let num++ else - [[ "sS" =~ ${1:$i:1} ]] && return 1 - [[ "tx" =~ ${1:$i:1} ]] && X+=('X') || X+=(' ') - [[ "tx" =~ ${1:$((i++)):1} ]] && let num++ + [[ "sS" =~ ${p_s:$i:1} ]] && return 1 + [[ "tx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') + [[ "tx" =~ ${p_s:$((i++)):1} ]] && let num++ fi p_n+="$num" done From 545e6efe3ff5dd940b0b22a55ef8343152ee9ef9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Jun 2020 09:40:46 -0400 Subject: [PATCH 4/9] better arg parsing, less errors --- share/adapters/oeis.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/share/adapters/oeis.sh b/share/adapters/oeis.sh index d57bf70..9273963 100755 --- a/share/adapters/oeis.sh +++ b/share/adapters/oeis.sh @@ -51,7 +51,8 @@ oeis() ( # . oeis # . oeis # . oeis - if [ $# -lt 3 ] + isNum='^[0-9]+$' + if [ $# -lt 3 ] && [[ ${1:1} =~ $isNum || ${2:1} =~ $isNum || ${1} =~ $isNum || ${2} =~ $isNum ]] && [[ ! ${1} =~ $isNum || ! ${2} =~ $isNum ]] then # Arg-Parse ID, Generate URL if echo ${1^^} | grep -q '[B-Z]' @@ -103,7 +104,7 @@ oeis() ( # Search unknown sequence else # Build URL - URL+="/search?q=signed%3A$(echo $@ | grep -v [a-z] | grep -v [A-Z] | tr ' ' ',')" + URL+="/search?q=signed%3A$(echo $@ | tr -sc '[:digit:]' ',')" curl $URL 2>/dev/null > $DOC # Sequence IDs grep -o '=id:.*&' $DOC \ From c01df365247585e9bc7b5d11774097e1a1e18307 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 10 Jun 2020 22:33:13 -0400 Subject: [PATCH 5/9] chmod.sh rrx--- is invalid string --- share/adapters/chmod.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index ccf41ad..d1f6696 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -66,19 +66,21 @@ chmod_calc(){ for (( i=0; i<${#p_s}; i+=0 )) do num=0 + [[ "r-" =~ ${p_s:$i:1} ]] || return 1 [[ ${p_s:$i:1} == 'r' ]] && R+=('X') || R+=(' ') [[ ${p_s:$((i++)):1} == 'r' ]] && let num++ num=$(( num << 1 )) + [[ "w-" =~ ${p_s:$i:1} ]] || return 1 [[ ${p_s:$i:1} == 'w' ]] && W+=('X') || W+=(' ') [[ ${p_s:$((i++)):1} == 'w' ]] && let num++ num=$(( num << 1 )) if [ $i -lt 6 ] then - [[ "tT" =~ ${p_s:$i:1} ]] && return 1 + [[ "sSx-" =~ ${p_s:$i:1} ]] || return 1 [[ "sx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') [[ "sx" =~ ${p_s:$((i++)):1} ]] && let num++ else - [[ "sS" =~ ${p_s:$i:1} ]] && return 1 + [[ "tTx-" =~ ${p_s:$i:1} ]] || return 1 [[ "tx" =~ ${p_s:$i:1} ]] && X+=('X') || X+=(' ') [[ "tx" =~ ${p_s:$((i++)):1} ]] && let num++ fi From 5bdf06963b465a404e045ed72155b1a55ab0cf67 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 11 Jun 2020 05:21:32 -0400 Subject: [PATCH 6/9] chmod.sh code readability --- share/adapters/chmod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index d1f6696..3c5e2e2 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -24,7 +24,7 @@ chmod_calc(){ do num=$(echo "obase=2;${p_n:$i:1}" | bc | xargs printf '%03d') # If 4 digit input -> process specials - if [[ ${#p_n} -eq 4 && $i -eq 0 ]] + if [ $i -eq 0 ] then [ ${num:0:1} -eq 1 ] && setuid='X' || setuid=' ' [ ${num:1:1} -eq 1 ] && setgid='X' || setgid=' ' From 8814488e2669ff0bfa298b4140f5511e16daffb6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 11 Jun 2020 05:25:28 -0400 Subject: [PATCH 7/9] chmod.sh '888' is now invalid --- share/adapters/chmod.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/share/adapters/chmod.sh b/share/adapters/chmod.sh index 3c5e2e2..0ddfb89 100755 --- a/share/adapters/chmod.sh +++ b/share/adapters/chmod.sh @@ -20,6 +20,7 @@ chmod_calc(){ if [[ $1 =~ ^-?[0-9]+$ && ${#1} -ge 1 && ${#1} -le 4 ]] then p_n=$(printf "%04s\n" "$1" | tr ' ' '0') + echo $p_n | grep -q '[8-9]' && return 1 for (( i=0; i<${#p_n}; i++ )) do num=$(echo "obase=2;${p_n:$i:1}" | bc | xargs printf '%03d') From ca9d5bc1772b438ce44d49747b65694f0d4c672b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 11 Jun 2020 05:34:24 -0400 Subject: [PATCH 8/9] new parsing was removing '-'. negative numbers now supported again --- share/adapters/oeis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/adapters/oeis.sh b/share/adapters/oeis.sh index 9273963..b823e4a 100755 --- a/share/adapters/oeis.sh +++ b/share/adapters/oeis.sh @@ -104,7 +104,7 @@ oeis() ( # Search unknown sequence else # Build URL - URL+="/search?q=signed%3A$(echo $@ | tr -sc '[:digit:]' ',')" + URL+="/search?q=signed%3A$(echo $@ | tr -sc '[:digit:]-' ',')" curl $URL 2>/dev/null > $DOC # Sequence IDs grep -o '=id:.*&' $DOC \ From 5c27a3bdb5616642bd23423c0e77cc1247d0f161 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 11 Jun 2020 07:22:41 -0400 Subject: [PATCH 9/9] Fixed 2 arg input bugs --- share/adapters/oeis.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/share/adapters/oeis.sh b/share/adapters/oeis.sh index b823e4a..18c458e 100755 --- a/share/adapters/oeis.sh +++ b/share/adapters/oeis.sh @@ -52,15 +52,15 @@ oeis() ( # . oeis # . oeis isNum='^[0-9]+$' - if [ $# -lt 3 ] && [[ ${1:1} =~ $isNum || ${2:1} =~ $isNum || ${1} =~ $isNum || ${2} =~ $isNum ]] && [[ ! ${1} =~ $isNum || ! ${2} =~ $isNum ]] + if [ $# -lt 3 ] && [[ ${1:1} =~ $isNum || ${2:1} =~ $isNum || ${1} =~ $isNum || ${2} =~ $isNum ]] && ! echo $1 | grep -q '[0-9]' || ! echo $2 | grep -q '[0-9]' then # Arg-Parse ID, Generate URL if echo ${1^^} | grep -q '[B-Z]' then - ID=$2 + ID=${2^^} LANGUAGE=$1 else - ID=$1 + ID=${1^^} LANGUAGE=$2 fi [[ ${ID:0:1} == 'A' ]] && ID=${ID:1}