]> gitweb.ps.run Git - chirp/blobdiff - src/main.zig
<input></input> -> <input />
[chirp] / src / main.zig
index cc3321686b188a3498ffdf7bc9f639e357753f5a..8cabda6e31c9ed010a599d71f820f5cbbe04b7be 100644 (file)
@@ -111,28 +111,19 @@ fn reencode(comptime T: type, text: []const u8) !T {
         const c = text[idx];
         if (c == '+') {
             try result.append(' ');
-        } else if (c == '%') {
-            // special case of &#...
-            // assume only &#, no &#x
-            if (idx + 6 < text.len and std.mem.eql(u8, text[idx .. idx + 6], "%26%23")) {
-                const num_start = idx + 6;
-                var num_end = num_start;
-                while (num_end < text.len and std.ascii.isDigit(text[num_end])) {
-                    num_end += 1;
-                }
+        } else if (c == '%' and idx + 2 < text.len) {
+            const allow = &[_]u8{ 0x26, 0x23, 0x3b, 0x0a };
 
-                if (num_end + 2 < text.len and
-                    text[num_end] == '%' and
-                    text[num_end + 1] == '3' and
-                    std.ascii.toLower(text[num_end + 2]) == 'b')
-                {
-                    try std.fmt.format(result.writer(), "&#{s};", .{text[num_start..num_end]});
-                    idx = num_end + 2;
-                    continue;
-                }
+            const escaped_value = std.fmt.parseUnsigned(u8, text[idx + 1 .. idx + 3], 16) catch continue;
+
+            if (escaped_value == 0x0d) {
+                try std.fmt.format(result.writer(), "<br />", .{});
+            } else if (std.mem.indexOfScalar(u8, allow, escaped_value) != null) {
+                try std.fmt.format(result.writer(), "{c}", .{escaped_value});
+            } else {
+                try std.fmt.format(result.writer(), "&#x{x};", .{escaped_value});
             }
 
-            try std.fmt.format(result.writer(), "&#x{s};", .{text[idx + 1 .. idx + 3]});
             idx += 2;
         } else {
             try result.append(c);
@@ -708,8 +699,8 @@ fn write_post(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, post_id: Po
             try res.write("<option value=\"{x}\">{s}{s}</option>", .{ id, name.constSlice(), if (list_view.has(post_id) catch false) " *" else "" });
         }
         try res.write("</select>", .{});
-        try res.write("<input type=\"hidden\" name=\"post_id\" value=\"{x}\"></input>", .{@intFromEnum(post_id)});
-        try res.write("<input type=\"submit\" value=\"Save\"></input>", .{});
+        try res.write("<input type=\"hidden\" name=\"post_id\" value=\"{x}\" />", .{@intFromEnum(post_id)});
+        try res.write("<input type=\"submit\" value=\"Save\" />", .{});
         try res.write("</form>", .{});
     }
 
@@ -789,8 +780,8 @@ fn write_profile(res: *http.Response, txn: lmdb.Txn, logged_in: ?Login, user: Us
             try res.write("<option value=\"{x}\">{s}{s}</option>", .{ id, name.constSlice(), if (list_view.has(user.id) catch false) " *" else "" });
         }
         try res.write("</select>", .{});
-        try res.write("<input type=\"hidden\" name=\"user_id\" value=\"{x}\"></input>", .{@intFromEnum(user.id)});
-        try res.write("<input type=\"submit\" value=\"Add to feed\"></input>", .{});
+        try res.write("<input type=\"hidden\" name=\"user_id\" value=\"{x}\" />", .{@intFromEnum(user.id)});
+        try res.write("<input type=\"submit\" value=\"Add to feed\" />", .{});
         try res.write("</form>", .{});
     }
     try res.write(