Skip to content

Commit

Permalink
Merge pull request #2682 from aG0aep6G/stride
Browse files Browse the repository at this point in the history
std.utf.stride: reject sequence lengths greater than 4
  • Loading branch information
MartinNowak committed Nov 12, 2014
2 parents 858296f + 4ce7db5 commit dc7eb9d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions posix.mak
Expand Up @@ -88,8 +88,8 @@ WEBSITE_DIR = ../web
DOC_OUTPUT_DIR = $(WEBSITE_DIR)/phobos-prerelease
BIGDOC_OUTPUT_DIR = /tmp
SRC_DOCUMENTABLES = index.d $(addsuffix .d,$(STD_MODULES) $(STD_NET_MODULES) $(STD_DIGEST_MODULES) $(STD_CONTAINER_MODULES) $(EXTRA_DOCUMENTABLES))
STDDOC = $(DOCSRC)/std.ddoc
BIGSTDDOC = $(DOCSRC)/std_consolidated.ddoc
STDDOC = $(DOCSRC)/std.ddoc $(DOCSRC)/macros.ddoc
BIGSTDDOC = $(DOCSRC)/std_consolidated.ddoc $(DOCSRC)/macros.ddoc
# Set DDOC, the documentation generator
DDOC=$(DMD) -m$(MODEL) -w -c -o- -version=StdDdoc \
-I$(DRUNTIME_PATH)/import $(DMDEXTRAFLAGS)
Expand Down
19 changes: 17 additions & 2 deletions std/utf.d
Expand Up @@ -138,7 +138,8 @@ unittest
$(D index) defaults to $(D 0) if none is passed.
Returns:
The number of bytes in the UTF-8 sequence.
The number of bytes in the UTF-8 sequence, a value between 1 and 4
(as per $(WEB tools.ietf.org/html/rfc3629#section-3, RFC 3629$(COMMA) section 3)).
Throws:
May throw a $(D UTFException) if $(D str[index]) is not the start of a
Expand Down Expand Up @@ -186,7 +187,7 @@ body
{
import core.bitop : bsr;
immutable msbs = 7 - bsr(~c);
if (msbs < 2 || msbs > 6)
if (msbs < 2 || msbs > 4)
throw new UTFException("Invalid UTF-8 sequence", index);
return msbs;
}
Expand Down Expand Up @@ -258,6 +259,20 @@ unittest
});
}

unittest // invalid start bytes
{
import std.exception: assertThrown;
immutable char[] invalidStartBytes = [
0b1111_1000, // indicating a sequence length of 5
0b1111_1100, // 6
0b1111_1110, // 7
0b1111_1111, // 8
0b1000_0000, // continuation byte
];
foreach(c; invalidStartBytes)
assertThrown!UTFException(stride([c]));
}


/++
$(D strideBack) returns the length of the UTF-8 sequence ending one code
Expand Down
2 changes: 1 addition & 1 deletion win32.mak
Expand Up @@ -61,7 +61,7 @@ DMD=dmd
## Location of where to write the html documentation files

DOCSRC = ../dlang.org
STDDOC = $(DOCSRC)/std.ddoc
STDDOC = $(DOCSRC)/std.ddoc $(DOCSRC)/macros.ddoc

DOC=..\..\html\d\phobos
#DOC=..\doc\phobos
Expand Down
2 changes: 1 addition & 1 deletion win64.mak
Expand Up @@ -61,7 +61,7 @@ DMD=dmd
## Location of where to write the html documentation files

DOCSRC = ../dlang.org
STDDOC = $(DOCSRC)/std.ddoc
STDDOC = $(DOCSRC)/std.ddoc $(DOCSRC)/macros.ddoc

DOC=..\..\html\d\phobos
#DOC=..\doc\phobos
Expand Down

0 comments on commit dc7eb9d

Please sign in to comment.