Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix rangeOfTextLists method to avoid accidental call by UIKit #1290

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Source/DTHTMLWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ - (void)_buildOutputAsHTMLFragment:(BOOL)fragment

for (DTCSSListStyle *oneList in currentListStyles)
{
NSRange listRange = [_attributedString rangeOfTextList:oneList atIndex:paragraphRange.location];
NSRange listRange = [_attributedString _DTRangeOfTextList:oneList atIndex:paragraphRange.location];

if (listRange.location == paragraphRange.location)
{
Expand Down
5 changes: 4 additions & 1 deletion Core/Source/NSAttributedString+DTCoreText.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@
/**
Returns the range of the given text list that contains the given location.

Prefix is used to avoid a presumed naming collision that causes this method
to be called unexpectedly by internal UIKit logic.

@param list The text list.
@param location The location in the text.
@returns The range of the given text list containing the location.
*/
- (NSRange)rangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location;
- (NSRange)_DTRangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location;

/**
Returns the range of the given text block that contains the given location.
Expand Down
4 changes: 2 additions & 2 deletions Core/Source/NSAttributedString+DTCoreText.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (NSInteger)itemNumberInTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)loc
DTCSSListStyle *outermostList = [textListsAtIndex objectAtIndex:0];

// get the range of all lists
NSRange totalRange = [self rangeOfTextList:outermostList atIndex:location];
NSRange totalRange = [self _DTRangeOfTextList:outermostList atIndex:location];

// get naked NSString
NSString *string = [[self string] substringWithRange:totalRange];
Expand Down Expand Up @@ -212,7 +212,7 @@ - (NSRange)_rangeOfObject:(id)object inArrayBehindAttribute:(NSString *)attribut
}
}

- (NSRange)rangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location
- (NSRange)_DTRangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location
{
NSParameterAssert(list);

Expand Down
8 changes: 4 additions & 4 deletions Test/Source/DTHTMLAttributedStringBuilderTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ - (void)testTextListRanges

DTCSSListStyle *outerList = [lists lastObject];

NSRange list1Range = [attributedString rangeOfTextList:outerList atIndex:0];
NSRange list1Range = [attributedString _DTRangeOfTextList:outerList atIndex:0];

XCTAssertTrue(!list1Range.location, @"lists should start at index 0");
XCTAssertTrue(list1Range.length, @"lists should range for entire string");
Expand All @@ -897,7 +897,7 @@ - (void)testTextListRanges
XCTAssertTrue([innerLists objectAtIndex:0] == outerList , @"list at index 0 in inner lists should be same as outer list");
}

NSRange list2Range = [attributedString rangeOfTextList:[innerLists lastObject] atIndex:innerRange.location];
NSRange list2Range = [attributedString _DTRangeOfTextList:[innerLists lastObject] atIndex:innerRange.location];
NSRange innerParagraph = [[attributedString string] paragraphRangeForRange:innerRange];

XCTAssertTrue(NSEqualRanges(innerParagraph, list2Range), @"Inner list range should be equal to inner paragraph");
Expand All @@ -919,7 +919,7 @@ - (void)testEmptyListItemWithSubList

[firstParagraphLists enumerateObjectsUsingBlock:^(DTCSSListStyle *oneList, NSUInteger idx, BOOL *stop) {

NSRange listRange = [attributedString rangeOfTextList:oneList atIndex:firstParagraphRange.location];
NSRange listRange = [attributedString _DTRangeOfTextList:oneList atIndex:firstParagraphRange.location];

NSRange commonRange = NSIntersectionRange(listRange, firstParagraphRange);

Expand All @@ -937,7 +937,7 @@ - (void)testEmptyListItemWithSubList

[secondParagraphLists enumerateObjectsUsingBlock:^(DTCSSListStyle *oneList, NSUInteger idx, BOOL *stop) {

NSRange listRange = [attributedString rangeOfTextList:oneList atIndex:secondParagraphRange.location];
NSRange listRange = [attributedString _DTRangeOfTextList:oneList atIndex:secondParagraphRange.location];

NSRange commonRange = NSIntersectionRange(listRange, secondParagraphRange);

Expand Down
8 changes: 4 additions & 4 deletions Test/Source/NSAttributedStringDTCoreTextTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ - (void)testListRange
XCTAssertFalse(effectiveList == newListStyle, @"Copy should have produced a different instance");

// test new list inside range
NSRange nonFoundRange = [attributedString rangeOfTextList:newListStyle atIndex:innerRange.location];
NSRange nonFoundRange = [attributedString _DTRangeOfTextList:newListStyle atIndex:innerRange.location];
NSRange expectedRange = NSMakeRange(NSNotFound, 0);
XCTAssertTrue(NSEqualRanges(nonFoundRange, expectedRange), @"Should not find other list inside");

// test new list outside range
nonFoundRange = [attributedString rangeOfTextList:newListStyle atIndex:1];
nonFoundRange = [attributedString _DTRangeOfTextList:newListStyle atIndex:1];
expectedRange = NSMakeRange(NSNotFound, 0);
XCTAssertTrue(NSEqualRanges(nonFoundRange, expectedRange), @"Should not find other list at index 1");

// test effective list inside range
NSRange foundRange = [attributedString rangeOfTextList:effectiveList atIndex:innerRange.location];
NSRange foundRange = [attributedString _DTRangeOfTextList:effectiveList atIndex:innerRange.location];
expectedRange = [[attributedString string] paragraphRangeForRange:innerRange];
XCTAssertTrue(NSEqualRanges(foundRange, expectedRange), @"Should find effective list around 'inner'");

// test effective list outside range
nonFoundRange = [attributedString rangeOfTextList:effectiveList atIndex:1];
nonFoundRange = [attributedString _DTRangeOfTextList:effectiveList atIndex:1];
expectedRange = NSMakeRange(NSNotFound, 0);
XCTAssertTrue(NSEqualRanges(nonFoundRange, expectedRange), @"Should not find effective list at index 1");
}
Expand Down