コード例 #1
0
        private void MatchUTF8SequenceOverrunTest(byte[] inbytes, int numBytes, bool isQuery, bool iriParsing)
        {
            Encoding noFallbackCharUTF8 = Encoding.GetEncoding(
                Encoding.UTF8.CodePage,
                new EncoderReplacementFallback(""),
                new DecoderReplacementFallback(""));

            char[] chars = noFallbackCharUTF8.GetChars(inbytes, 0, numBytes);

            Assert.False(
                chars.Length == 0,
                "Invalid test: MatchUTF8Sequence cannot be called when no Unicode characters can be decoded.");

            // dest is guaranteed to have space for the escaped version of all characters (in the form of %HH).
            char[] dest           = new char[inbytes.Length * 3];
            char[] unescapedChars = new char[inbytes.Length];
            chars.CopyTo(unescapedChars, 0);

            int expectedLength     = inbytes.Length * 3;
            ValueStringBuilder vsb = HeapCheck.CreateFilledPooledArray(expectedLength);

            vsb.Length = 32;
            UriHelper.MatchUTF8Sequence(
                ref vsb,
                unescapedChars,
                chars.Length,
                inbytes,
                numBytes,
                isQuery,
                iriParsing);

            // Check for buffer under and overruns.
            HeapCheck.ValidatePadding(vsb, expectedLength);
        }
コード例 #2
0
        private string EscapeUnescapeTestComponent(string uriInput, UriComponents component)
        {
            string    ret = null;
            HeapCheck hc  = new HeapCheck(uriInput);

            unsafe
            {
                fixed(char *pInput = hc.HeapBlock)
                {
                    ret = IriHelper.EscapeUnescapeIri(pInput + hc.Offset, 0, uriInput.Length, component);
                }
            }

            // check for buffer under and overruns
            hc.ValidatePadding();

            return(ret);
        }
コード例 #3
0
        private void MatchUTF8SequenceOverrunTest(byte[] inbytes, int numBytes, bool isQuery, bool iriParsing)
        {
            Encoding noFallbackCharUTF8 = Encoding.GetEncoding(
                Encoding.UTF8.CodePage,
                new EncoderReplacementFallback(""),
                new DecoderReplacementFallback(""));

            char[] chars = noFallbackCharUTF8.GetChars(inbytes, 0, numBytes);

            Assert.False(
                chars.Length == 0,
                "Invalid test: MatchUTF8Sequence cannot be called when no Unicode characters can be decoded.");

            // dest is guaranteed to have space for the escaped version of all characters (in the form of %HH).
            char[] dest           = new char[inbytes.Length * 3];
            char[] unescapedChars = new char[inbytes.Length];
            chars.CopyTo(unescapedChars, 0);

            HeapCheck hc = new HeapCheck(dest);

            unsafe
            {
                fixed(char *pInput = hc.HeapBlock)
                {
                    int offset = hc.Offset;

                    UriHelper.MatchUTF8Sequence(
                        pInput,
                        hc.HeapBlock,
                        ref offset,
                        unescapedChars,
                        chars.Length,
                        inbytes,
                        numBytes,
                        isQuery,
                        iriParsing);
                }
            }

            // Check for buffer under and overruns.
            hc.ValidatePadding();
        }
コード例 #4
0
        private void MatchUTF8SequenceOverrunTest(byte[] inbytes, int numBytes, bool isQuery, bool iriParsing)
        {
            Encoding noFallbackCharUTF8 = Encoding.GetEncoding(
                Encoding.UTF8.CodePage,
                new EncoderReplacementFallback(""),
                new DecoderReplacementFallback(""));

            char[] chars = noFallbackCharUTF8.GetChars(inbytes, 0, numBytes);

            Assert.False(
                chars.Length == 0,
                "Invalid test: MatchUTF8Sequence cannot be called when no Unicode characters can be decoded.");

            // dest is guaranteed to have space for the escaped version of all characters (in the form of %HH).
            char[] dest = new char[inbytes.Length * 3];
            char[] unescapedChars = new char[inbytes.Length];
            chars.CopyTo(unescapedChars, 0);

            HeapCheck hc = new HeapCheck(dest);

            unsafe
            {
                fixed (char* pInput = hc.HeapBlock)
                {
                    int offset = hc.Offset;
                    UriHelper.MatchUTF8Sequence(
                        pInput,
                        hc.HeapBlock,
                        ref offset,
                        unescapedChars,
                        chars.Length,
                        inbytes,
                        numBytes,
                        isQuery,
                        iriParsing);
                }
            }

            // Check for buffer under and overruns.
            hc.ValidatePadding();
        }
コード例 #5
0
        private string EscapeUnescapeTestComponent(string uriInput, UriComponents component)
        {
            string ret = null;
            HeapCheck hc = new HeapCheck(uriInput);

            unsafe
            {
                fixed (char* pInput = hc.HeapBlock)
                {
                    ret = IriHelper.EscapeUnescapeIri(pInput + hc.Offset, 0, uriInput.Length, component);
                }
            }

            // check for buffer under and overruns
            hc.ValidatePadding();

            return ret;
        }