Skip to content

Implement URI Handling Functions #894

Closed

Description

@Razican

ECMASCript feature
We currently lack the implementation of some built-in global functions used for URI encoding/decoding. You can find these functions in the spec here.

The 4 functions to implement would be these:

In those links you can find example code that should work after this implementation.

Implementation tips
We should probably create a new module here for these functions. An example of a built-in global function implementation can be seen here.

Activity

  1. added
    A-Enhancement
    Good First Issue
    Hacktoberfest
    C-Builtins
    E-Medium
    on Oct 19, 2020
  2. sidntrivedi commented on Oct 24, 2020

    @sidntrivedi

    Hey @Razican , I would like to work on it. Thanks :)

  3. Razican commented on Jan 11, 2021

    @Razican
    MemberAuthor

    Hi @sidntrivedi012 how is this going?

  4. captain-yossarian commented on Jan 22, 2021

    @captain-yossarian

    I will be happy to take a look if @sidntrivedi012 don't mind

  5. tofpie commented on Jan 24, 2021

    @tofpie
    Contributor
  6. captain-yossarian commented on Jan 25, 2021

    @captain-yossarian

    @Razican @tofpie Should/Can I use this percent_encoding crrate ?

  7. Razican commented on Jan 26, 2021

    @Razican
    MemberAuthor

    @Razican @tofpie Should/Can I use this percent_encoding crrate ?

    Hi, yes, if it makes sense to use it, feel free :)

  8. jedel1043 commented on Sep 20, 2021

    @jedel1043
    Member

    Unassigned the issue by @captain-yossarian's request. For anyone interested, feel free to ping us if you want to work on this😁

  9. jtara1 commented on Oct 1, 2021

    @jtara1

    I'll take a look at this, please assign to me.

  10. jedel1043 commented on Oct 1, 2021

    @jedel1043
    Member

    @jtara1 I've asigned it to you. Let us know if you need some pointers to get started :)

  11. jtara1 commented on Oct 2, 2021

    @jtara1

    I got something working with that crate ^
    but I'm trying to just follow their algo directly in the ecma spec now

    What's the return values for this function? https://github.com/jtara1/boa/blob/8ba500a26afdad8e200c9990b375664b5c04a97a/boa/src/builtins/string/mod.rs#L36

    e: looks like @joshwd36 implemented that, what do the return values of (u32, u8, bool) represent for code_point_at func?

  12. jedel1043 commented on Oct 2, 2021

    @jedel1043
    Member

    code_point_at just represents the operation CodePointAt from the spec. But maybe we could rewrite it to be more idiomatic with descriptive enum returns instead of bools and u8s

  13. jtara1 commented on Oct 2, 2021

    @jtara1

    the spec answered my question with

    Return the Record { [[CodePoint]], [[CodeUnitCount]], [[IsUnpairedSurrogate]] }.

    thanks

  14. jtara1 commented on Oct 3, 2021

    @jtara1

    So far the hardest part of this is figuring out what the transformation algo (for singles & pairs) for code point -> utf-8 encoded byte(s) is. https://en.wikipedia.org/wiki/UTF-8 which actually seems like the most thorough explanation for this

    I'm also checking the node.js implementation of this https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/deps/v8/src/strings/uri.cc#L279

    and

    void AddEncodedOctetToBuffer(uint8_t octet, std::vector<uint8_t>* buffer) {
      buffer->push_back('%');
      buffer->push_back(HexCharOfValue(octet >> 4));
      buffer->push_back(HexCharOfValue(octet & 0x0F));
    }
    
    void EncodeSingle(uc16 c, std::vector<uint8_t>* buffer) {
      char s[4] = {};
      int number_of_bytes;
      number_of_bytes =
          unibrow::Utf8::Encode(s, c, unibrow::Utf16::kNoPreviousCharacter, false);
      for (int k = 0; k < number_of_bytes; k++) {
        AddEncodedOctetToBuffer(s[k], buffer);
      }
    }
    
    void EncodePair(uc16 cc1, uc16 cc2, std::vector<uint8_t>* buffer) {
      char s[4] = {};
      int number_of_bytes =
          unibrow::Utf8::Encode(s, unibrow::Utf16::CombineSurrogatePair(cc1, cc2),
                                unibrow::Utf16::kNoPreviousCharacter, false);
      for (int k = 0; k < number_of_bytes; k++) {
        AddEncodedOctetToBuffer(s[k], buffer);
      }
    }

    e: my answer may lie here https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/deps/v8/src/strings/unicode-inl.h#L144 still sorting through things

  15. joshwd36 commented on Oct 3, 2021

    @joshwd36
    Contributor

    Would it be worth looking into #736 again? It seems that the implementation will be pretty closely tied to the encoding

  16. jedel1043 commented on Oct 5, 2021

    @jedel1043
    Member

    Would it be worth looking into #736 again? It seems that the implementation will be pretty closely tied to the encoding

    Yeah, maybe. We could reevaluate if there's a way to adapt our regex to consume UTF-16, then change the definition of JsString.

  17. removed their assignment
    on Feb 15, 2022
  18. added a commit that references this issue on Sep 18, 2022
    779384d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-EnhancementC-BuiltinsE-MediumGood First IssueHacktoberfest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions