<commit_before>package unfiltered.oauth

object Signatures {
  import OAuth._
  
  type Params = Map[String, Seq[String]]
  
  val signatures = Map("HMAC-SHA1" -> HmacSha1)
  
  implicit val encoding = "UTF-8"
  
  trait ParamNormalizing {
    /** http://tools.ietf.org/html/rfc5849#section-3.4.1.3 */
    def normalizedParams(p: Params) =
      (new collection.immutable.TreeMap[String, Seq[String]] ++ p) map { case (k, v) => v.toList.sort (_<_) map { 
          case e => k + "=" + e  } mkString "&" }  mkString "&"
  }
  
  trait Signature extends Encoding with ParamNormalizing with Combining {
    def sign(method: String, url: String, params: Params, consumerSec: String, tokenSec: String): String
  }
  <commit_msg>decode and re-encode before ordering and combining params<commit_after>package unfiltered.oauth

object Signatures {
  import OAuth._
  
  type Params = Map[String, Seq[String]]
  
  val signatures = Map("HMAC-SHA1" -> HmacSha1, "PLAINTEXT" -> PlainText)
  
  implicit val encoding = "UTF-8"
  
  trait ParamNormalizing { self: Encoding =>
    /** decode then re-encode */
    private def recode(p: Params) =
      (Map.empty[String, Seq[String]].withDefaultValue(Nil) /: p)((rc,e) =>
        rc + (encode(decode(e._1)) -> (e._2 map { str: String => encode(decode(str)) }) )
      )
 
    /** http://tools.ietf.org/html/rfc5849#section-3.4.1.3 */
    def normalizedParams(p: Params) =
      (new collection.immutable.TreeMap[String, Seq[String]] ++ recode(p)) map { 
        case (k, v) => v.toList sort (_<_) map { 
          case e => k + "=" + e 
        } mkString "&" 
      } mkString "&"
  }
  
  trait Signature extends Encoding with ParamNormalizing with Combining {
    def sign(method: String, url: String, params: Params, consumerSec: String, tokenSec: String): String
  }

  object PlainText extends Signature {
    def sign(method: String, url: String, p: Params, consumerSec: String, tokenSec: String) =
      combine(consumerSec, tokenSec)
  }
  
{'fraction_non_alphanumeric': 0.13954659949622167, 'fraction_numerical': 0.012090680100755667, 'mean_word_length': 3.103305785123967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '655654', 'n_tokens_mistral': 688, 'n_tokens_neox': 676, 'n_words': 166}