Skip to content

Commit bdfd5f5

Browse files
authored
Merge pull request #379 from Vkt0r/route-overlapping
Route overlapping issue
2 parents 57faa5d + 16f3d42 commit bdfd5f5

File tree

13 files changed

+115
-48
lines changed

13 files changed

+115
-48
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
TEST_REPORTS: /tmp/test-results
77
LANG: en_US.UTF-8
88
macos:
9-
xcode: 10.1.0
9+
xcode: 10.2.0
1010
steps:
1111
- checkout
1212
- run:

Sources/Errno.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
public class Errno {
1111

1212
public class func description() -> String {
13-
return String(cString: UnsafePointer(strerror(errno)))
13+
// https://forums.developer.apple.com/thread/113919
14+
return String(cString: strerror(errno))
1415
}
1516
}

Sources/HttpRouter.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77

88
import Foundation
99

10-
1110
open class HttpRouter {
1211

13-
public init() {
14-
}
12+
public init() {}
1513

1614
private class Node {
15+
16+
/// The children nodes that form the route
1717
var nodes = [String: Node]()
18+
19+
/// Define whether or not this node is the end of a route
20+
var isEndOfRoute: Bool = false
21+
22+
/// The closure to handle the route
1823
var handler: ((HttpRequest) -> HttpResponse)? = nil
1924
}
2025

@@ -69,15 +74,20 @@ open class HttpRouter {
6974
}
7075

7176
private func inflate(_ node: inout Node, generator: inout IndexingIterator<[String]>) -> Node {
72-
if let pathSegment = generator.next() {
73-
if let _ = node.nodes[pathSegment] {
74-
return inflate(&node.nodes[pathSegment]!, generator: &generator)
77+
78+
var currentNode = node
79+
80+
while let pathSegment = generator.next() {
81+
if let nextNode = currentNode.nodes[pathSegment] {
82+
currentNode = nextNode
83+
} else {
84+
currentNode.nodes[pathSegment] = Node()
85+
currentNode = currentNode.nodes[pathSegment]!
7586
}
76-
var nextNode = Node()
77-
node.nodes[pathSegment] = nextNode
78-
return inflate(&nextNode, generator: &generator)
7987
}
80-
return node
88+
89+
currentNode.isEndOfRoute = true
90+
return currentNode
8191
}
8292

8393
private func findHandler(_ node: inout Node, params: inout [String: String], generator: inout IndexingIterator<[String]>) -> ((HttpRequest) -> HttpResponse)? {
@@ -103,7 +113,7 @@ open class HttpRouter {
103113
var currentIndex = index + 1
104114
let variableNodes = node.nodes.filter { $0.0.first == ":" }
105115
if let variableNode = variableNodes.first {
106-
if variableNode.1.nodes.count == 0 {
116+
if currentIndex == count && variableNode.1.isEndOfRoute {
107117
// if it's the last element of the pattern and it's a variable, stop the search and
108118
// append a tail as a value for the variable.
109119
let tail = generator.joined(separator: "/")

XCode/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
23
import SwifterTests
34

45
var tests = [XCTestCaseEntry]()

XCode/Swifter.xcodeproj/project.pbxproj

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -617,27 +617,29 @@
617617
isa = PBXProject;
618618
attributes = {
619619
LastSwiftUpdateCheck = 1010;
620-
LastUpgradeCheck = 1000;
620+
LastUpgradeCheck = 1020;
621621
ORGANIZATIONNAME = "Damian Kołakowski";
622622
TargetAttributes = {
623623
043660C121FED34100497989 = {
624624
CreatedOnToolsVersion = 10.1;
625+
LastSwiftMigration = 1020;
625626
ProvisioningStyle = Manual;
626627
};
627628
043660D921FED3A300497989 = {
628629
CreatedOnToolsVersion = 10.1;
630+
LastSwiftMigration = 1020;
629631
ProvisioningStyle = Manual;
630632
};
631633
269B47861D3AAAE20042D137 = {
632-
LastSwiftMigration = 1000;
634+
LastSwiftMigration = 1020;
633635
};
634636
7AE893E61C05127900A29F63 = {
635637
CreatedOnToolsVersion = 7.1;
636-
LastSwiftMigration = 1000;
638+
LastSwiftMigration = 1020;
637639
};
638640
7AE893FA1C0512C400A29F63 = {
639641
CreatedOnToolsVersion = 7.1;
640-
LastSwiftMigration = 1000;
642+
LastSwiftMigration = 1020;
641643
};
642644
7C839B6D19422CFF003A6950 = {
643645
CreatedOnToolsVersion = 6.0;
@@ -649,13 +651,13 @@
649651
};
650652
7CCD875B1C66099B0068099B = {
651653
CreatedOnToolsVersion = 7.2;
652-
LastSwiftMigration = 1000;
654+
LastSwiftMigration = 1020;
653655
};
654656
};
655657
};
656658
buildConfigurationList = 7C839B6919422CFF003A6950 /* Build configuration list for PBXProject "Swifter" */;
657659
compatibilityVersion = "Xcode 3.2";
658-
developmentRegion = English;
660+
developmentRegion = en;
659661
hasScannedForEncodings = 0;
660662
knownRegions = (
661663
en,
@@ -946,7 +948,7 @@
946948
PRODUCT_NAME = "$(TARGET_NAME)";
947949
PROVISIONING_PROFILE_SPECIFIER = "";
948950
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
949-
SWIFT_VERSION = 4.2;
951+
SWIFT_VERSION = 5.0;
950952
};
951953
name = Debug;
952954
};
@@ -974,7 +976,7 @@
974976
PRODUCT_BUNDLE_IDENTIFIER = oss.SwiftermacOSTests;
975977
PRODUCT_NAME = "$(TARGET_NAME)";
976978
PROVISIONING_PROFILE_SPECIFIER = "";
977-
SWIFT_VERSION = 4.2;
979+
SWIFT_VERSION = 5.0;
978980
};
979981
name = Release;
980982
};
@@ -1000,7 +1002,7 @@
10001002
PROVISIONING_PROFILE_SPECIFIER = "";
10011003
SDKROOT = appletvos;
10021004
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
1003-
SWIFT_VERSION = 4.2;
1005+
SWIFT_VERSION = 5.0;
10041006
TARGETED_DEVICE_FAMILY = 3;
10051007
TVOS_DEPLOYMENT_TARGET = 12.1;
10061008
};
@@ -1028,7 +1030,7 @@
10281030
PRODUCT_NAME = "$(TARGET_NAME)";
10291031
PROVISIONING_PROFILE_SPECIFIER = "";
10301032
SDKROOT = appletvos;
1031-
SWIFT_VERSION = 4.2;
1033+
SWIFT_VERSION = 5.0;
10321034
TARGETED_DEVICE_FAMILY = 3;
10331035
TVOS_DEPLOYMENT_TARGET = 12.1;
10341036
};
@@ -1054,7 +1056,7 @@
10541056
PRODUCT_NAME = Swifter;
10551057
SDKROOT = appletvos;
10561058
SKIP_INSTALL = YES;
1057-
SWIFT_VERSION = 4.2;
1059+
SWIFT_VERSION = 5.0;
10581060
TARGETED_DEVICE_FAMILY = 3;
10591061
TVOS_DEPLOYMENT_TARGET = 9.0;
10601062
VERSIONING_SYSTEM = "apple-generic";
@@ -1083,7 +1085,7 @@
10831085
PRODUCT_NAME = Swifter;
10841086
SDKROOT = appletvos;
10851087
SKIP_INSTALL = YES;
1086-
SWIFT_VERSION = 4.2;
1088+
SWIFT_VERSION = 5.0;
10871089
TARGETED_DEVICE_FAMILY = 3;
10881090
TVOS_DEPLOYMENT_TARGET = 9.0;
10891091
VERSIONING_SYSTEM = "apple-generic";
@@ -1111,7 +1113,7 @@
11111113
PRODUCT_NAME = Swifter;
11121114
SDKROOT = iphoneos;
11131115
SKIP_INSTALL = YES;
1114-
SWIFT_VERSION = 4.2;
1116+
SWIFT_VERSION = 5.0;
11151117
VERSIONING_SYSTEM = "apple-generic";
11161118
VERSION_INFO_PREFIX = "";
11171119
};
@@ -1138,7 +1140,7 @@
11381140
PRODUCT_NAME = Swifter;
11391141
SDKROOT = iphoneos;
11401142
SKIP_INSTALL = YES;
1141-
SWIFT_VERSION = 4.2;
1143+
SWIFT_VERSION = 5.0;
11421144
VERSIONING_SYSTEM = "apple-generic";
11431145
VERSION_INFO_PREFIX = "";
11441146
};
@@ -1166,7 +1168,7 @@
11661168
PRODUCT_NAME = Swifter;
11671169
SDKROOT = macosx;
11681170
SKIP_INSTALL = YES;
1169-
SWIFT_VERSION = 4.2;
1171+
SWIFT_VERSION = 5.0;
11701172
VERSIONING_SYSTEM = "apple-generic";
11711173
VERSION_INFO_PREFIX = "";
11721174
};
@@ -1195,7 +1197,7 @@
11951197
PRODUCT_NAME = Swifter;
11961198
SDKROOT = macosx;
11971199
SKIP_INSTALL = YES;
1198-
SWIFT_VERSION = 4.2;
1200+
SWIFT_VERSION = 5.0;
11991201
VERSIONING_SYSTEM = "apple-generic";
12001202
VERSION_INFO_PREFIX = "";
12011203
};
@@ -1207,6 +1209,7 @@
12071209
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
12081210
ALWAYS_SEARCH_USER_PATHS = NO;
12091211
APPLICATION_EXTENSION_API_ONLY = YES;
1212+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
12101213
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
12111214
CLANG_CXX_LIBRARY = "libc++";
12121215
CLANG_ENABLE_MODULES = YES;
@@ -1268,6 +1271,7 @@
12681271
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
12691272
ALWAYS_SEARCH_USER_PATHS = NO;
12701273
APPLICATION_EXTENSION_API_ONLY = YES;
1274+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
12711275
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
12721276
CLANG_CXX_LIBRARY = "libc++";
12731277
CLANG_ENABLE_MODULES = YES;
@@ -1406,7 +1410,7 @@
14061410
PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOSTests;
14071411
PRODUCT_NAME = "$(TARGET_NAME)";
14081412
SDKROOT = iphoneos;
1409-
SWIFT_VERSION = 4.2;
1413+
SWIFT_VERSION = 5.0;
14101414
};
14111415
name = Debug;
14121416
};
@@ -1424,7 +1428,7 @@
14241428
PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOSTests;
14251429
PRODUCT_NAME = "$(TARGET_NAME)";
14261430
SDKROOT = iphoneos;
1427-
SWIFT_VERSION = 4.2;
1431+
SWIFT_VERSION = 5.0;
14281432
};
14291433
name = Release;
14301434
};

XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwifterMac.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwifteriOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwifteriOSTests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftermacOSTests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftertvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1000"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)