Skip to content

Commit f12327a

Browse files
Avoids application crash with duplicate keys in info dictionary (#12)
1 parent 953bf14 commit f12327a

File tree

4 files changed

+397
-1
lines changed

4 files changed

+397
-1
lines changed

Sources/App/Parsing/ConstraintsParser+Info.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension ConstraintsParser {
2020
static let keyValuePair = infoInstance.map { ($0.className, $0) }.otherwise((quotableKey.thenSkip(character(":")).then(infoInstance)))
2121
.named("key value pair")
2222
static let commaSeparator = string(", ")
23-
static let keyValuePairs = many(keyValuePair, separator: commaSeparator).map { Dictionary(uniqueKeysWithValues: $0) }
23+
static let keyValuePairs = many(keyValuePair, separator: commaSeparator).map { Dictionary($0, uniquingKeysWith: { $1 }) }
2424
static let namesDictionary = names.skipThen(wss).skipThen(keyValuePairs).thenSkip(wss)
2525
static let emptyInfo = character("(").skipThen(active).thenSkip(character(")")).map { _ in return [String: Instance]() }
2626
static let nonEmptyInfo = character("(").skipThen(optional(active.then(commaSeparator))).skipThen(namesDictionary).thenSkip(wss).thenSkip(character(")"))
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
HTTP/1.1 200 OK
2+
content-type: text/html; charset=utf-8
3+
content-length: 4749
4+
5+
6+
7+
8+
9+
10+
<!DOCTYPE html>
11+
<html lang="en">
12+
<head>
13+
<title>WTF Auto Layout?</title>
14+
15+
<meta charset="UTF-8">
16+
<meta name="viewport" content="width=device-width, initial-scale=1">
17+
18+
<!-- Favicons -->
19+
<link rel="icon" type="image/png" href="/images/Icon_16x16.png" sizes="16x16">
20+
<link rel="icon" type="image/png" href="/images/Icon_32x32.png" sizes="32x32">
21+
<link rel="icon" type="image/png" href="/images/Icon_96x96.png" sizes="96x96">
22+
23+
<!-- App Icons -->
24+
<link rel="apple-touch-icon" href="/images/Icon_120x120.png">
25+
<link rel="apple-touch-icon" sizes="180x180" href="/images/Icon_180x180.png">
26+
<link rel="apple-touch-icon" sizes="152x152" href="/images/Icon_152x152.png">
27+
<link rel="apple-touch-icon" sizes="167x167" href="/images/Icon_167x167.png">
28+
29+
<!-- OG/Twitter Metadata -->
30+
<meta property="og:type" content="website" />
31+
<meta property="og:title" content="WTF Auto Layout?">
32+
<meta property="og:description" content="Make sense of cryptic Auto Layout error logs.">
33+
<meta property="og:image" content="/images/Card.png">
34+
<meta property="og:url" content="https://www.wtfautolayout.com">
35+
<meta property="og:site_name" content="WTF Auto Layout?">
36+
<meta name="twitter:card" content="summary">
37+
<meta name="twitter:site" content="@jpmmusic" />
38+
39+
<!-- Styles -->
40+
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
41+
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3-theme-black.css">
42+
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
43+
<link rel="stylesheet" href="/styles/main.css">
44+
45+
<!-- Google Analytics -->
46+
<script>
47+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
48+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
49+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
50+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
51+
52+
ga('create', 'UA-78016335-2', 'auto');
53+
ga('send', 'pageview', 'error');
54+
55+
</script>
56+
57+
</head>
58+
<body class="w3-theme-l5">
59+
60+
61+
62+
63+
<!-- Navbar -->
64+
65+
<div class="w3-top">
66+
<div class="w3-bar w3-theme-dark w3-left-align w3-large">
67+
<a href="/" class="tab w3-bar-item w3-button w3-theme-l1 w3-hover-dark-grey">Home</a>
68+
<a href="/about" class="tab w3-bar-item w3-button w3-hover-dark-grey">About</a>
69+
</div>
70+
</div>
71+
72+
<div style="height:20px;"></div>
73+
74+
<!-- Main content -->
75+
76+
<div class="w3-main main">
77+
<div class="w3-content w3-container w3-padding-32">
78+
79+
<!-- Hero -->
80+
81+
<div class="hero flex-container w3-padding-16">
82+
<img class="logo w3-padding-small" width="80" src="images/wtf-logo.svg" alt="WTF Auto Layout logo"/>
83+
<div class="w3-padding-small">
84+
<h2>Why The Failure,<br /><strong>Auto Layout</strong>?</h2>
85+
</div>
86+
</div>
87+
88+
89+
<!-- Form -->
90+
91+
<div class="w3-container">
92+
<form action="/" class="w3-container" method="post">
93+
<label class="w3-label">Paste your constraint error log here:</label>
94+
<textarea class="mono w3-input w3-border w3-round w3-hover-light-gray" wrap="off" rows="10" name="constraintlog" required="required" placeholder="Paste your constraint error logs: just the part surrounded by ( and )" autofocus>(
95+
&quot;&lt;NSLayoutConstraint:0x608000696990 V:[ListViewItemLabel...]-(7)-[ListViewImage-a...] (active, names: ListViewItemLabel...:0x7f950028efe0, ListViewItemLabel...:0x7f950028e5b0 )&gt;&quot;,
96+
)</textarea>
97+
<a href="/?example=true" class="w3-button w3-round-large w3-green w3-margin-top">Example</a>
98+
<button class="w3-button w3-right w3-round-large w3-blue w3-margin-top">Go!</button>
99+
</form>
100+
101+
<div class="alert mono w3-panel w3-margin w3-pale-red"><pre>INVALID CONSTRAINT:
102+
Missing info for ListViewImage-a....</pre></div>
103+
</div>
104+
105+
106+
</div>
107+
</div>
108+
109+
<!-- Footer -->
110+
111+
<div style="height:64px;"></div>
112+
113+
<footer>
114+
<div class="w3-bar w3-theme-l1 w3-small w3-hide-small">
115+
<div class="w3-bar-item w3-left" style="color:white">Built using <a href="https://swift.org/">Swift</a>, <a href="https://vapor.codes">Vapor</a>, <a href="https://github.com/johnpatrickmorgan/Sparse">Sparse</a> and <a href="https://www.w3schools.com/w3css/">W3.CSS</a>
116+
</div>
117+
</div>
118+
<div class="w3-bar w3-theme-dark w3-small">
119+
<div class="w3-bar-item w3-left">View source on <a href="https://www.github.com/johnpatrickmorgan/wtfautolayout" target="_blank">GitHub</a>
120+
</div>
121+
<a href="https://www.github.com/johnpatrickmorgan" class="w3-bar-item w3-hover-opacity w3-small w3-right" target="_blank">johnpatrickmorgan</a>
122+
</div>
123+
</footer>
124+
125+
</body>
126+
</html>
127+
128+
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
HTTP/1.1 200 OK
2+
content-type: text/html; charset=utf-8
3+
content-length: 4821
4+
5+
6+
7+
8+
9+
10+
<!DOCTYPE html>
11+
<html lang="en">
12+
<head>
13+
<title>WTF Auto Layout?</title>
14+
15+
<meta charset="UTF-8">
16+
<meta name="viewport" content="width=device-width, initial-scale=1">
17+
18+
<!-- Favicons -->
19+
<link rel="icon" type="image/png" href="/images/Icon_16x16.png" sizes="16x16">
20+
<link rel="icon" type="image/png" href="/images/Icon_32x32.png" sizes="32x32">
21+
<link rel="icon" type="image/png" href="/images/Icon_96x96.png" sizes="96x96">
22+
23+
<!-- App Icons -->
24+
<link rel="apple-touch-icon" href="/images/Icon_120x120.png">
25+
<link rel="apple-touch-icon" sizes="180x180" href="/images/Icon_180x180.png">
26+
<link rel="apple-touch-icon" sizes="152x152" href="/images/Icon_152x152.png">
27+
<link rel="apple-touch-icon" sizes="167x167" href="/images/Icon_167x167.png">
28+
29+
<!-- OG/Twitter Metadata -->
30+
<meta property="og:type" content="website" />
31+
<meta property="og:title" content="WTF Auto Layout?">
32+
<meta property="og:description" content="Make sense of cryptic Auto Layout error logs.">
33+
<meta property="og:image" content="/images/Card.png">
34+
<meta property="og:url" content="https://www.wtfautolayout.com">
35+
<meta property="og:site_name" content="WTF Auto Layout?">
36+
<meta name="twitter:card" content="summary">
37+
<meta name="twitter:site" content="@jpmmusic" />
38+
39+
<!-- Styles -->
40+
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
41+
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3-theme-black.css">
42+
<link rel="stylesheet" href="https://code.cdn.mozilla.net/fonts/fira.css">
43+
<link rel="stylesheet" href="/styles/main.css">
44+
45+
<!-- Google Analytics -->
46+
<script>
47+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
48+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
49+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
50+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
51+
52+
ga('create', 'UA-78016335-2', 'auto');
53+
ga('send', 'pageview', 'error');
54+
55+
</script>
56+
57+
</head>
58+
<body class="w3-theme-l5">
59+
60+
61+
62+
63+
<!-- Navbar -->
64+
65+
<div class="w3-top">
66+
<div class="w3-bar w3-theme-dark w3-left-align w3-large">
67+
<a href="/" class="tab w3-bar-item w3-button w3-theme-l1 w3-hover-dark-grey">Home</a>
68+
<a href="/about" class="tab w3-bar-item w3-button w3-hover-dark-grey">About</a>
69+
</div>
70+
</div>
71+
72+
<div style="height:20px;"></div>
73+
74+
<!-- Main content -->
75+
76+
<div class="w3-main main">
77+
<div class="w3-content w3-container w3-padding-32">
78+
79+
<!-- Hero -->
80+
81+
<div class="hero flex-container w3-padding-16">
82+
<img class="logo w3-padding-small" width="80" src="images/wtf-logo.svg" alt="WTF Auto Layout logo"/>
83+
<div class="w3-padding-small">
84+
<h2>Why The Failure,<br /><strong>Auto Layout</strong>?</h2>
85+
</div>
86+
</div>
87+
88+
89+
<!-- Form -->
90+
91+
<div class="w3-container">
92+
<form action="/" class="w3-container" method="post">
93+
<label class="w3-label">Paste your constraint error log here:</label>
94+
<textarea class="mono w3-input w3-border w3-round w3-hover-light-gray" wrap="off" rows="10" name="constraintlog" required="required" placeholder="Paste your constraint error logs: just the part surrounded by ( and )" autofocus>(
95+
&quot;&lt;NSLayoutConstraint:0x608000696990 V:[ListViewItemLabel...]-(7)-[ListViewItemLabel...] (active, names: ListViewItemLabel...:0x7f950028efe0, ListViewItemLabel...:0x7f950028e5b0 )&gt;&quot;,
96+
)</textarea>
97+
<a href="/?example=true" class="w3-button w3-round-large w3-green w3-margin-top">Example</a>
98+
<button class="w3-button w3-right w3-round-large w3-blue w3-margin-top">Go!</button>
99+
</form>
100+
101+
<div class="alert mono w3-panel w3-margin w3-pale-red"><pre>UNEXPECTED INPUT:
102+
Line 3, Column 1
103+
)
104+
^
105+
EXPECTED:
106+
&#39;&quot;&#39; in &quot;&lt;
107+
whitespace or newline in constraint separator
108+
</pre></div>
109+
</div>
110+
111+
112+
</div>
113+
</div>
114+
115+
<!-- Footer -->
116+
117+
<div style="height:64px;"></div>
118+
119+
<footer>
120+
<div class="w3-bar w3-theme-l1 w3-small w3-hide-small">
121+
<div class="w3-bar-item w3-left" style="color:white">Built using <a href="https://swift.org/">Swift</a>, <a href="https://vapor.codes">Vapor</a>, <a href="https://github.com/johnpatrickmorgan/Sparse">Sparse</a> and <a href="https://www.w3schools.com/w3css/">W3.CSS</a>
122+
</div>
123+
</div>
124+
<div class="w3-bar w3-theme-dark w3-small">
125+
<div class="w3-bar-item w3-left">View source on <a href="https://www.github.com/johnpatrickmorgan/wtfautolayout" target="_blank">GitHub</a>
126+
</div>
127+
<a href="https://www.github.com/johnpatrickmorgan" class="w3-bar-item w3-hover-opacity w3-small w3-right" target="_blank">johnpatrickmorgan</a>
128+
</div>
129+
</footer>
130+
131+
</body>
132+
</html>
133+
134+

0 commit comments

Comments
 (0)