Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Url Path Decoder #448

Closed
wants to merge 1 commit into from
Closed

Url Path Decoder #448

wants to merge 1 commit into from

Conversation

troydai
Copy link
Contributor

@troydai troydai commented Oct 20, 2015

Addressing: aspnet/KestrelHttpServer#124
/cc @Tratcher @blowdart @lodejard

Note:

  • Unescaping every thing except /. %2F will be leave in the string.
  • If a sequence can't be correctly decoded under UTF8, just leave them as is.
  • Supposed to be O(n). Need more performance testing to prove.

Follow up:

  • Still working on more tests.
  • More performance tuning will happen as result of performance test.
  • Also, I'm looking at a change to potentially decode the string in place without allocate a new char array.
  • Also, need security review.

@troydai troydai force-pushed the trdai/kes124 branch 2 times, most recently from 3607cd4 to 60d50aa Compare October 20, 2015 08:20
/// <summary>
/// Find the next % in the sequence. If % is not found, return the sequence length.
/// </summary>
private static int NextPercentage(int start, string source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetNextEncoded?

@troydai troydai changed the title [Prototype] Url Path Decoder Url Path Decoder Oct 20, 2015
}
}

private static bool TryGetUnescapedAscii(char first, char second, out char result)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name and purpose are out of sync. You don't fail if it's > 0x7F and you keep doing bitwise operation on the resulting char. How about changing it to TryGetUnescapedByte with an out byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

  • Name
  • Out a byte

@troydai
Copy link
Contributor Author

troydai commented Oct 20, 2015

Ok, I make one significant update. I added a function to do inplace decoding to avoid allocating additional char array.

new DecoderExceptionFallback());

/// <summary>
/// Unescape a url char array in place. Returns the length of the result.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use standard doc comment tags like <returns>

@troydai
Copy link
Contributor Author

troydai commented Oct 20, 2015

Ping @blowdart for security review.

@Eilon
Copy link
Contributor

Eilon commented Oct 21, 2015

Yes, why is this here? This needs to be in CoreFx.

@Eilon
Copy link
Contributor

Eilon commented Oct 21, 2015

In fact, @Tratcher is in the process of gutting this entire project: #449

@troydai
Copy link
Contributor Author

troydai commented Oct 21, 2015

Sure, this can be moved to corefx eventually. I'm wondering what's the process of adding this to corefx and how long does it take since I have four days to fix the corresponding Kestrel issue 124.

May be we can do this parallel. I'll open an PR on corefx begin adding this there in the meantime let's add this here first to get by the rc1.

@Eilon
Copy link
Contributor

Eilon commented Oct 21, 2015

Make this more internal-ish in this repo then, as opposed to making it public-ish. (I don't care about actual accessibility, but I want it to look like it's going away, e.g. in a .Internal namespace.

@troydai
Copy link
Contributor Author

troydai commented Oct 21, 2015

Will do.

@troydai
Copy link
Contributor Author

troydai commented Oct 21, 2015

Ping every one: @muratg @Eilon @Tratcher @halter73 @lodejard

Features:
- Minimal memory allocation.
- Support decode string (in the form of char array) in place
- UTF8 verification
- Skip unescapse '%2F'
using System;
using System.Text;

namespace Microsoft.Extensions.WebEncoders.Internals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Internal

@troydai
Copy link
Contributor Author

troydai commented Oct 22, 2015

Close this one for now. I'm aiming at handle this entirely in Kestrel by itself.

@troydai troydai closed this Oct 22, 2015
@troydai
Copy link
Contributor Author

troydai commented Oct 22, 2015

@troydai troydai deleted the trdai/kes124 branch October 26, 2015 22:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants