Commit Graph

905 Commits

Author SHA1 Message Date
Hüseyin ASLITÜRK
df8fd4e8c8 Test: Fix json parse test from unicode string 2020-06-16 13:15:17 +02:00
Hüseyin ASLITÜRK
0aad21fff2 AK: JsonParser, replace char type to u32 for code point 2020-06-16 13:15:17 +02:00
Kevin Meyer
e0f4fdc9b4 AK: Assert non-empty Utf32View, when initialized with non-zero length
This was useful in debugging a nullptr dereference, which was happening
through later, but was caused by this inconsistent initialization.
2020-06-15 22:32:18 +02:00
Matthew Olsson
e8e728454c AK: JsonParser improvements
- Parsing invalid JSON no longer asserts
    Instead of asserting when coming across malformed JSON,
    JsonParser::parse now returns an Optional<JsonValue>.
- Disallow trailing commas in JSON objects and arrays
- No longer parse 'undefined', as that is a purely JS thing
- No longer allow non-whitespace after anything consumed by the initial
  parse() call. Examples of things that were valid and no longer are:
    - undefineddfz
    - {"foo": 1}abcd
    - [1,2,3]4
- JsonObject.for_each_member now iterates in original insertion order
2020-06-13 12:43:22 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Sergey Bugaev
f1566ed4c6 AK: Remove useless casts 2020-06-12 16:08:45 +02:00
Sergey Bugaev
3ff651323c AK: Ensure RefCounted types are never copied or moved
Before this, it has been possible to assign a RefCounted object to another
RefCounted object. Hilariosly (or sadly), that copied the refcount among
the other fields, meaning the target value ended up with a wrong refcount.

Ensure this never happens by disallowing copies and moves for RefCounted types.
2020-06-12 16:08:45 +02:00
Sergey Bugaev
0ff3c1c34d AK: Assert refcount doesn't overflow
We don't really have a good way to prevent this kind of overflow,
but let's at least immediately panic in this case.
2020-06-12 16:08:45 +02:00
Sergey Bugaev
c80e657dda AK: Switch RefCounted to atomic refcounting
This fixes all sorts of race conditions, primarily in the kernel, where till
now it's been possible to obtain either double free or use-after-free by
exploiting refcounting races.
2020-06-12 16:08:45 +02:00
Sergey Bugaev
583108004c AK: Use unsigned int for refcount
And while fixing all the tests that look at ref_count(),
sneak in a fix for the test suite name.
2020-06-12 16:08:45 +02:00
Sergey Bugaev
0466810638 AK: Ensure we never use OwnPtr<> with RefCounted types 2020-06-12 16:08:45 +02:00
Sergey Bugaev
5624f8d8ee AK: ALWAYS_INLINE most Atomic<T> methods 2020-06-12 16:08:45 +02:00
Sergey Bugaev
4d65466f02 AK: Fix missing ptrdiff_t in non-Serenity builds
We have to include <stddef.h> to get its definition.
2020-06-12 16:08:45 +02:00
Andreas Kling
ff6de8a169 AK: URL should urldecode data: URL payloads
Otherwise we can end up with percent-encoded nonsense in base64 data
which does not decode correctly.
2020-06-10 17:45:34 +02:00
Andreas Kling
86eeac86a4 AK: Add basic percent encoder/decoder (urlencode and urldecode) 2020-06-07 21:05:05 +02:00
Andreas Kling
83ee76a53e AK: Add StringView::{begin,end} so we can range-for over StringViews 2020-06-07 21:05:05 +02:00
Andreas Kling
ec83555b87 AK: Don't try to complete relative data: URLs 2020-06-07 19:09:03 +02:00
Sergey Bugaev
9e046bcef1 AK: Fix printf("%c", 0)
It was me who has broken this, sorry ;(
2020-06-06 14:42:31 +02:00
Andreas Kling
23dad305e9 AK: Allow default-constructing Utf8View and Utf8CodepointIterator 2020-06-04 21:12:17 +02:00
Andreas Kling
d4bbc00901 AK: Add StringBuilder::append_codepoint(u32)
Also, implement append(Utf32View) using it.
2020-06-04 21:12:17 +02:00
Tom
93b9832fac AK: Add atomic free functions
This allows for using atomic operations on any variables,
not only those wrapped in AK::Atomic<T>
2020-06-04 18:15:23 +02:00
Hüseyin ASLITÜRK
8e9776165f AK: JSON, Escape spacial character in string serialization 2020-06-03 21:52:40 +02:00
Andreas Kling
f249f07699 AK: Add operator== and hash traits for URL 2020-06-01 21:50:07 +02:00
Sergey Bugaev
c3db694d9b AK: Always inline some Checked methods
Once again, we need to hint the compiler that it should inline the function, and
then it is able to eliminate the assertion.
2020-05-31 21:38:50 +02:00
Andreas Kling
4e80f22cc0 AK: Make some StringView constructors constexpr 2020-05-30 17:47:50 +02:00
Andreas Kling
1ef5d609d9 AK+LibC: Add TODO() as an alternative to ASSERT_NOT_REACHED()
I've been using this in the new HTML parser and it makes it much easier
to understand the state of unfinished code branches.

TODO() is for places where it's okay to end up but we need to implement
something there.

ASSERT_NOT_REACHED() is for places where it's not okay to end up, and
something has gone wrong.
2020-05-30 11:31:49 +02:00
Andreas Kling
643464c455 AK: Make {String,FlyString}::is_one_of() const
Also, make the zero-argument variant private since it's not meant to be
called by clients directly.
2020-05-30 11:31:49 +02:00
Marcin Gasperowicz
9a4ee9aa1a Lagom: Adjust AK, LibCore and LibTLS to build on MacOS 2020-05-30 00:36:13 +02:00
Paul Redmond
4d4e578edf Ports: Fix CMake-based ports
The SDL port failed to build because the CMake toolchain filed pointed
to the old root. Now the toolchain file assumes that the Root is in
Build/Root.

Additionally, the AK/ and Kernel/ headers need to be installed in the
root too.
2020-05-29 20:21:10 +02:00
Emanuele Torre
937d0be762 Meta: Add a script check the presence of "#pragma once" in header files
.. and make travis run it.

I renamed check-license-headers.sh to check-style.sh and expanded it so
that it now also checks for the presence of "#pragma once" in .h files.

It also checks the presence of a (single) blank line above and below the
"#pragma once" line.

I also added "#pragma once" to all the files that need it: even the ones
we are not check.
I also added/removed blank lines in order to make the script not fail.

I also ran clang-format on the files I modified.
2020-05-29 07:59:45 +02:00
AnotherTest
f9bf2c7e78 AK: Add StringView::split_view() taking a StringView
Since the task of splitting a string via another is pretty common, we
might as well have this overload of split_view() as well.
2020-05-28 11:01:08 +02:00
Andreas Kling
9a113b0229 AK: Add a simple randomness API
This can be used in code that builds on non-Serenity platforms.
2020-05-27 12:25:46 +02:00
Andreas Kling
16accb71a3 AK: Mark some popular String member functions ALWAYS_INLINE
I don't wanna see String::length() in a profile, jeez. :^)
2020-05-26 22:49:06 +02:00
Sergey Bugaev
602c3fdb3a AK: Rename FileSystemPath -> LexicalPath
And move canonicalized_path() to a static method on LexicalPath.

This is to make it clear that FileSystemPath/canonicalized_path() only
perform *lexical* canonicalization.
2020-05-26 14:35:10 +02:00
Brian Gianforcaro
27360f1f20 Build: Fix cmake test runner, so it knows when tests fail
The CMake runner looks at the return code if you don't set
the pattern. Since the AK test suite setup doesn't use return
codes, we were missing test failures.
2020-05-26 13:38:20 +02:00
Brian Gianforcaro
71deafe476 AK: Temporarily disable failing relative_paths tests in FileSystemPath suite
It appears this got broken in a3e4dfdf98.
I filed a tracking bug https://github.com/SerenityOS/serenity/issues/2388
2020-05-26 13:38:20 +02:00
Brian Gianforcaro
e5045b62b8 AK: Expand string tests to include ends_with case insensitivity 2020-05-26 13:17:19 +02:00
Brian Gianforcaro
129462cca7 AK: Unify FlyString/StringView::ends_with implementation on StringUtils::ends_with
This creates a unified implementation of ends_with with case sensitivity
across String/StringView/FlyString.
2020-05-26 13:17:19 +02:00
Brian Gianforcaro
332f96e7ca AK: Add case insensitive String::ends_with support
FileSystemPath::has_extension was jumping through hoops and allocating
memory to do a case insensitive comparison needlessly. Extend the
existing String::ends_with method to allow the caller to specify the
case sensitivity required.
2020-05-26 13:17:19 +02:00
Brian Gianforcaro
8e4b858b3f AK: Move String::ends_with implementation to StringUtils
Centralizing so it can be used by other string implementations
2020-05-26 13:17:19 +02:00
Andreas Kling
5e77517e6e AK: Add String::is_one_of(...)
This allows you to compare a string against an arbitrary number of
other strings with a single call.
2020-05-25 19:51:23 +02:00
Andreas Kling
dd924b730a Kernel+LibC: Fix various build issues introduced by ssize_t
Now that ssize_t is derived from size_t, we have to
2020-05-23 15:27:33 +02:00
Andreas Kling
8fe4512f8e AK: Fix inconsistent signature for dbgputstr() 2020-05-23 15:25:43 +02:00
Andreas Kling
4177953530 AK: Simplify Types.h a little bit 2020-05-23 15:25:43 +02:00
Andreas Kling
e90ecdda48 AK: Add MakeSigned<T> helper template 2020-05-23 15:25:43 +02:00
Andreas Kling
6cefb96e98 AK: Allow NumericLimits.h to compile in a kernel context
We explicitly disallow floating point numbers during kernel compilation
so we have to #ifdef out those parts here.
2020-05-23 15:25:43 +02:00
FalseHonesty
b1e4f70173 AK: Fix URL::complete_url behaviour for when a fragment is passed
Previously, passing a fragment string ("#section3") to the complete_url
method would result in a URL that looked like
"file:///home/anon/www/#section3" which was obviously incorrect. Now the
result looks like "file:///home/anon/www/afrag.html#section3".
2020-05-23 11:53:25 +02:00
Sergey Bugaev
a3e4dfdf98 AK: Fix .. handling in FileSystemPath
We shouldn't just drop leading ..-s for relative paths. At the same time,
we should handle paths like

    ../foo/../../bar

correctly: the first .. after the foo cancels out the foo, but the second
one should get treated as a leading one and not get dropped.

Note that since this path resolution is purely lexical, it's never going to be
completely correct with respect to symlinks and other filesystem magic. Better
don't use it when dealing with files.
2020-05-22 23:55:35 +02:00
Andreas Kling
a1db1e6664 AK: Make JsonValue and JsonObjectSerializer speak int/long/long long
While width-oriented integer types are nicer from the programmer's
perspective, we have to accept that C++ thinks in int/long/long long.
2020-05-22 13:57:23 +02:00
Hüseyin ASLITÜRK
738235574f AK: StringUtils, add "convert_to_uint_from_hex" method
New method to convert hex string unsigned integer.
2020-05-21 01:19:42 +02:00