From 1b7e8dd04bacb563aec73aee4c1ecf9de57a9321 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 28 Mar 2017 16:57:47 +0200 Subject: [PATCH 1/2] Editorial: remove labels from IPv6 parser Fixes part of #282. --- url.bs | 117 +++++++++++++++++++++++++-------------------------------- 1 file changed, 52 insertions(+), 65 deletions(-) diff --git a/url.bs b/url.bs index b8e65bcb..aedd72a5 100644 --- a/url.bs +++ b/url.bs @@ -552,8 +552,7 @@ then runs these steps:
  • -

    Main: while c is not the - EOF code point: +

    While c is not the EOF code point:

    1. If piece pointer is eight, validation error, return failure. @@ -565,8 +564,8 @@ then runs these steps:

    2. If compress pointer is non-null, validation error, return failure.

    3. Increase pointer and piece pointer by one, set - compress pointer to piece pointer, - and then jump to Main. + compress pointer to piece pointer, and then + continue.
  • Let value and length be 0. @@ -579,95 +578,87 @@ then runs these steps: and increase pointer and length by one.

  • -

    Switching on c: +

    If c is U+002E (.), then: -

    -
    U+002E (.) -
    -
      -
    1. If length is 0, validation error, return failure. +

        +
      1. If length is 0, validation error, return failure. -

      2. Decrease pointer by length. +

      3. Decrease pointer by length. -

      4. Jump to IPv4. -

      +
    2. If piece pointer is greater than six, validation error, return + failure. -

      U+003A (:) -
      -
        -
      1. Increase pointer by one. +

      2. Let numbersSeen be 0. -

      3. If c is the EOF code point, validation error, return failure. -

      +
    3. +

      While c is not the EOF code point: -

      Anything but the EOF code point -

      Validation error, return failure. -

    +
      +
    1. Let value be null. -

    2. Set piece to value. +

    3. +

      If numbersSeen is greater than 0, then: -

    4. Increase piece pointer by one. -

    +
      +
    1. If c is a U+002E (.) and numbersSeen is less than 4, then increase + pointer by one. -

    2. If c is the EOF code point, jump to - Finale. +

    3. Otherwise, validation error, return failure. +
    -
  • IPv4: if - piece pointer is greater than six, validation error, return failure. +

  • If c is not an ASCII digit, validation error, return failure. + -

  • Let numbersSeen be 0. +

  • +

    While c is an ASCII digit: -

  • -

    While c is not the EOF code point: +

      +
    1. Let number be c interpreted as decimal number. -

        -
      1. Let value be null. +

      2. +

        If value is null, set value to number. -

      3. -

        If numbersSeen is greater than 0, then: +

        Otherwise, if value is 0, validation error, return failure. -

          -
        1. If c is a U+002E (.) and numbersSeen is less than 4, then increase - pointer by one. +

          Otherwise, set value to value × 10 + number. -

        2. Otherwise, validation error, return failure. -
        +
      4. Increase pointer by one. -

      5. If c is not an ASCII digit, validation error, return failure. - +

      6. If value is greater than 255, validation error, return failure. +

      -
    2. -

      While c is an ASCII digit: +

    3. Set piece to piece × 0x100 + value. -

        -
      1. Let number be c interpreted as decimal number. +

      2. Increase numbersSeen by one. -

      3. -

        If value is null, set value to number. +

      4. If numbersSeen is 2 or 4, then increase piece pointer by one. -

        Otherwise, if value is 0, validation error, return failure. +

      5. If c is the EOF code point and numbersSeen is not 4, + validation error, return failure. +

      + +
    4. Break. +

    -

    Otherwise, set value to value × 10 + number. +

  • +

    Otherwise, if c is U+003A (:): +

    1. Increase pointer by one. -

    2. If value is greater than 255, validation error, return failure. +

    3. If c is the EOF code point, validation error, return failure.

    -
  • Set piece to - piece × 0x100 + value. - -

  • Increase numbersSeen by one. +

  • Otherwise, if c is not the EOF code point, Validation error, return + failure. -

  • If numbersSeen is 2 or 4, then increase piece pointer by one. +

  • Set piece to value. -

  • If c is the EOF code point and numbersSeen is not 4, - validation error, return failure. +

  • Increase piece pointer by one.

  • -

    Finale: if - compress pointer is non-null, then: +

    If compress pointer is non-null, then:

    1. Let swaps be @@ -688,10 +679,6 @@ then runs these steps:

    2. Return address.

    -

    To be clear, Main, -IPv4, and Finale are markers. They serve -no purpose other than being a location the algorithm can jump to. -


    The opaque-host parser takes a string From b41b65a8bcdc9560ed1bc0f1446b0fa081029894 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 7 Apr 2017 17:46:13 +0200 Subject: [PATCH 2/2] rename inner value variable to ipv4Piece --- url.bs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/url.bs b/url.bs index aedd72a5..d7b910ce 100644 --- a/url.bs +++ b/url.bs @@ -594,7 +594,7 @@ then runs these steps:

    While c is not the EOF code point:

      -
    1. Let value be null. +

    2. Let ipv4Piece be null.

    3. If numbersSeen is greater than 0, then: @@ -616,18 +616,20 @@ then runs these steps:

    4. Let number be c interpreted as decimal number.

    5. -

      If value is null, set value to number. +

      If ipv4Piece is null, then set ipv4Piece to number. -

      Otherwise, if value is 0, validation error, return failure. +

      Otherwise, if ipv4Piece is 0, validation error, return failure. -

      Otherwise, set value to value × 10 + number. +

      Otherwise, set ipv4Piece to ipv4Piece × 10 + + number.

    6. Increase pointer by one. -

    7. If value is greater than 255, validation error, return failure. +

    8. If ipv4Piece is greater than 255, validation error, return + failure.

    -
  • Set piece to piece × 0x100 + value. +

  • Set piece to piece × 0x100 + ipv4Piece.

  • Increase numbersSeen by one. @@ -649,7 +651,7 @@ then runs these steps:

  • If c is the EOF code point, validation error, return failure. -

  • Otherwise, if c is not the EOF code point, Validation error, return +

  • Otherwise, if c is not the EOF code point, validation error, return failure.

  • Set piece to value.