Skip to content

Commit

Permalink
support decode url escaped key
Browse files Browse the repository at this point in the history
Signed-off-by: disksing <[email protected]>
  • Loading branch information
disksing committed Dec 22, 2020
1 parent 5c5d0ac commit 3ff4120
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/base64"
"encoding/hex"
"net/url"
"strconv"
"strings"

Expand All @@ -22,6 +23,7 @@ var rules = []Rule{
DecodeLiteral,
DecodeBase64,
DecodeIntegerBytes,
DecodeURLEscaped,
}

func DecodeHex(n *Node) *Variant {
Expand Down Expand Up @@ -173,3 +175,17 @@ func DecodeIntegerBytes(n *Node) *Variant {
children: []*Node{N("key", b)},
}
}

func DecodeURLEscaped(n *Node) *Variant {
if n.typ != "key" {
return nil
}
s, err := url.PathUnescape(string(n.val))
if err != nil || s == string(n.val) {
return nil
}
return &Variant{
method: "decode url encoded",
children: []*Node{N("key", []byte(s))},
}
}

0 comments on commit 3ff4120

Please sign in to comment.