gesistsa/adaR

`url_decode2` is not NA aware

Closed this issue · 5 comments

adaR::url_decode2(NA)
#> [1] "NA"

Created on 2023-09-27 with reprex v2.0.2

Fixing this can also enable decoding in C++.

@chainsawriot Do you mean something like

CharacterVector Rcpp_ada_get(const CharacterVector& url_vec, std::function<ada_string(ada_url)> func, bool decode) {
  unsigned int n = url_vec.length();
  CharacterVector out(n);
  for (int i = 0; i < url_vec.length(); i++) {
    String s = url_vec[i];
    const char* input = s.get_cstring();
    ada_url url = ada_parse(input, std::strlen(input));
    if (!ada_is_valid(url)) {
      out[i] = NA_STRING;
    } else {
      out[i] = charsub(func(url));
    }
  }
  if(decode){
    return(url_decode2(out))
  }else{
    return (out);
}
}
url_decode2(NULL)

kills R.

@schochastics Would you mind me changing url_decode2 with an R wrapper to filter the NULL case?

CharacterVector url_decode2(CharacterVector& url) {
  if (url.isNULL()) {
    CharacterVector output(0);
    return output;
  }
}

url_decode2(NULL) still kills this. Tried also Rf_isNull. It can't even pass the first line.

@chainsawriot no go ahead and make that change