`k` is being encoded here, but the brackets used below on lines 295 and 300 aren't.  TBH, I don't know if this is okay or not.  If you think `[` and `]` are safe to use in a URL, then this code is fine.  If not, then you may have to replace them with `%5b` and `%5d`