Changelog — SafeCoder.CommonKit
All notable changes to the library. Versions follow Semantic Versioning. Each version lists what was Added, Changed and Fixed; a breaking change says so.
[1.4.0]
Added
- Added
FilePlace, the places an application keeps files in —Uploads,Temporary,Images,Videos,Audio,Media,Documents,Imports,Exports,Archives— each a folder under one root set inCkSettings.DefaultFileRoot,appsettings.jsonor an environment variable, or a folder of its own set inCkSettings.FileRoot. Nothing is set as shipped. - Added file operations to
CkFile, each inside a place and never outside it:Exists,Read,ReadOrNull,Write,Copy,Move,Delete,Size,SizeOrNull,FilesandFullPath. A file is never left half-written, and an existing one is replaced only withoverwrite: true. - Added rules per place: the extensions it takes (
CkSettings.FileExtensions) and the largest file it accepts (CkSettings.FileMaxBytes, 2 MB by default inCkSettings.DefaultMaxFileBytes). A file whose content does not match its extension is refused, and programs, scripts and web pages are never accepted (CkSettings.BlockedExtensions).CkFile.AllowedExtensions,BlockedExtensions,MaxBytesandIsAllowedanswer the rules in force. - Added
CkFile.SniffType, the type a file's bytes prove,IsOfType,ExtensionForandUniqueName. - Added
CkPayload.UseInput, which hands the request an application is serving toCkPayloadonce per request, from the application's middleware, andCkPayload.Input, the default text of everyCkPayloadreader: called with no text,FromJson(),FromForm(),FromQuery()and the others read that request. Anullis still no value.
Changed
- Breaking. Renamed
CkDictionary.ToDateTime,ToDateOnly,ToGuidandToEnum<TEnum>toDateTime,DateOnly,GuidandEnum<TEnum>. Rename the calls; nothing else changes. - Removed
CkSettings.MaxHtmlPasses, which no method used;CkSettings.DefaultHtmlPassesis the one setting for how deeplyCkText.Htmldecodes entities. - Changed
CkWeb.Urlto refuse a host that ends in a number but is not an IPv4 address, such as1.2.3.4.5orexample.123, as browsers do. A host that is one, such as127.1, is written as the dotted address. - Changed
CkWeb.Urland the otherCkWebmethods to refuse a bracketed IPv6 host that has text after the]other than a port, such ashttp://[::1]x/, and an embedded IPv4 address with a leading zero, such ashttp://[::ffff:1.2.3.04]/, as .NET 11 does. - Changed
CkWeb.Urland the otherCkWebmethods to refuse a host that holds an invisible or control character or a non-ASCII digit, rather than cleaning it, and a host name that cannot be written in ASCII. - Changed
CkWeb.Explain, and the reason the throw switch gives, to say "not an http or https URL" for any value that opens with another scheme and "not a valid host name" for a bracketed host holding a character outside ASCII, before the runtime's own parser has a say; the values were refused before, with a reason that could depend on the runtime.
Fixed
- Fixed an issue where
CkPayload.FromFormcould accept multipart fields beyond the input limit. - Breaking fix.
CkDictionaryreaders now match keys case-sensitively in every dictionary, including dictionaries configured to ignore case. - Fixed an issue where
CkGeo.DistanceandIsWithincould disagree about equivalent locations. -
Fixed an issue where
CkFile.Filescould list links that the file readers refuse. -
Fixed an issue where
CkNumber.Clampcould answer the lower bound for a 128-bit value above the top when both bounds were too close to tell apart as decimals. - Fixed an issue where
CkFile.FileName,IsSafeFileName,RelativePathandIsRelativePathdid not treatCOM0,LPT0andCOM¹toLPT³as reserved Windows names. - Fixed an issue where
CkDateTime.ToDateTime,CkDate.ToDateOnlyand the other date methods refused ISO 8601 text with a space, minutes and a zone, such as2026-08-31 14:05+02:00. - Fixed an issue where
CkDateTime.ExplainandCkDate.Explaincould say a date was outside the calendar when only its zone was wrong, as in2026-08-31Z. - Fixed an issue where
CkDateTime.Add,AddDays,AddMonths,AddYears,StartOfDayandStartOfNextDaycould answer the wrong moment when the result fell on a day a zone skipped, such as 30 December 2011 in Samoa; the time now moves on past the gap. - Fixed an issue where a value read with an
assumeZoneon a day the zone skipped was read as a real moment instead of being refused. - Fixed an issue where
CkWeb.IsPublicHostcould accept some host names that point to an internal address. - Fixed an issue where
CkIP.IsPublic,IsInternalandCkWeb.IsPublicHostcould judge the IPv6 benchmarking block2001:2::/48, the IPv4-translated form::ffff:0:a.b.c.d, the local-use NAT64 block64:ff9b:1::/48, the IPv4-compatible form::a.b.c.dand the ISATAP form…:5efe:a.b.c.dwrapping an internal IPv4 address public. - Fixed an issue where
CkWeb.UrlandRemoveQuerycould hand out a URL longer thanUrlaccepts. - Fixed an issue where
CkWeb.Domain,IsPublicHost,IsIpHost,SameOriginandInDomainscould fail on a host thatUrlaccepted. - Fixed an issue where
CkWeb.Domain,SameOriginandInDomainscould include the zone id of an IPv6 host. - Fixed an issue where
CkWeb.Urland the otherCkWebmethods could accept a host that, once written in ASCII, holds a character no host name may hold, such as a|typed as its full-width look-alike.
[1.3.2]
Changed
- Breaking. The library targets .NET 9 instead of .NET 8, so an application on .NET 8 can no longer reference it.
- Changed
CkSettings.DefaultAssumeZone: once set, everyDateTimethe library hands out is on that zone's clock instead of UTC, so a value read and saved again never shifts.Iso8601andUnixstill write the true moment. Left null, as shipped, nothing changes.
Fixed
- Fixed an issue where a placeholder date such as 1900-01-01 could be read as a real date when an
assumeZonewas set. - Fixed an issue where
CkDate.IsPlaceholdercould disagree with the readers about a placeholder.
[1.3.1]
Changed
- A
zoneorassumeZonethe library does not know now counts as UTC instead of refusing the value.
Fixed
- Fixed an issue where
CkDictionary.ToDateTimehanded back aDateTimenot marked as UTC for a missing entry. - Fixed an issue where
CkDictionary.ToDateTimeandToDateOnlycould hand back a placeholderfallbacksuch as 1900-01-01. - Fixed an issue where
CkDateTime.IsIso8601could accept a moment before year one. - Fixed an issue where
CkDate.Explain,IsDateandIsPlaceholdercould answer for the day before when given anassumeZone. - Fixed an issue where a
CkDatemethod given azonecould accept a moment past the end of year 9999.
[1.3.0]
CkDate is split in two — CkDate for calendar days, the new CkDateTime for moments — a
breaking change for callers of the methods that moved. CkMoney gains the calculations a
payment needs.
Added
CkDateTime, for moments, handed out in UTC: the methods that moved fromCkDate(see Changed), plusAdd,AddYears,AddMonths,AddDays,AddHours,AddMinutes,AddSeconds,StartOfDay,StartOfNextDay,IsPast,IsFuture,IsBetween,IsDateTime,SameDayandExplain, all safe across daylight saving.CkSettings.DefaultZoneandDefaultAssumeZone— the application's time zone, set once — and azoneparameter on everyCkDatemethod that answers a day and onCkDictionary.ToDateOnly.CkDate.Add,AddDays,AddMonths,AddYears,AddWeekdays,MonthsBetween,WeekdaysBetween,WeekOfYear,StartOfWeek,EndOfWeek,StartOfQuarter,EndOfQuarter,StartOfYearandEndOfYear;CkSettings.MaxHolidaysandMaxWeekdaysToAdd.CkMoney.Allocate,Subtract,Divide,Convert,Display,Decimals,NumericCodeandCurrencyOf;textCaseonCurrency;decimalsandscaleonMinorUnits,FromMinorUnits,FormatandIsRounded, withCkSettings.MaxMoneyDecimals. Everycurrencyparameter also reads the numeric code, such as "978".- The currencies
XCG,VEDandKPW. CkCountryreads "Vatican" as VA.CkIntl.CallingCode.CkGeo.ToWkt,ToGeoJson,BoundsAroundandDestination;CkSettings.BoundsMarginDegrees.
Changed
- Breaking:
CkDateis split in two.ToDateTime,ToDateTimeOrNull,ToTimeOnly,ToTimeOnlyOrNull,Unix,InZone,TimeAgo,HasTime,IsTimeandIsIso8601moved toCkDateTime: replaceCkDate.withCkDateTime.at each call.Iso8601,Format,IsBeforeandIsAfterare in both, to the day inCkDateand to the moment inCkDateTime. - Breaking for some calls. The new
zoneparameter ofCkDateandcountryparameter ofCkIntl's phone methods sit before the optional ones, so a call that passed those by position must now name them. CkIntl.Phone,IsPhone,SamePhone,PhoneMaskandExplaintake acountryfor a national number:Phone("020 7946 0958", country: "GB")is"+442079460958".Phonealso readstel:links.CkIntl.PostalCodeandIsPostalCodeknow 181 countries and territories, up from 52.CkGeo.TryParse,LatitudeandLongituderead WKT and GeoJSON points.CkMoney.Explaintakes an optionalcurrency.- When a key repeats in a JSON payload, the last value wins.
- A bare number reads as a Unix timestamp up to the end of year 9999, where it stopped at 2099.
CkText.Betweenis capped atCkSettings.MaxHtmlInputLength.CkFile.IsSafeFileNameis false for a name that contains an invisible character.
Fixed
- Breaking for some inputs. A date with no time of day is no longer moved to the day before
by
assumeZone. - Breaking for some inputs.
CkMoneyrefuses an amount whose text names a different currency from the one asked for, instead of reading it with the wrong decimals, andSameAmount,IsAtLeast,IsAtMost,IsBetweenandTotalno longer mix currencies. - Fixed an issue where
CkDateTime.ToDateTime,Add,AddDays,AddMonths,AddYears,StartOfDayandStartOfNextDaycould answer a moment at the calendar's edge instead of refusing it. - Fixed an issue where
assumeZonemoved a moment written with a one-digit offset such as+2:00. - Fixed an issue where
CkFile.FileNamecould cut an over-long name in the middle of a character. - Fixed an issue where
CkFile.FromBase64decoded text thatIsBase64refuses. - Fixed an issue where
CkWeb.AddQuerycould return a URL longer thanUrlaccepts. - Fixed an issue where
CkIP.Maskmasked an IPv4 address written in IPv6 form as"0:0:0:***". - Fixed an issue where
CkIP.IsPublicandCkWeb.IsPublicHostsaid true for some internal addresses. - Fixed an issue where some markup could survive
CkText.String,Html,Name,AddressandToAscii. - Fixed an issue where
CkText.Htmlkept some control characters. - Fixed an issue where
CkText.Maskcould leave an invisible character or an emoji visible. - Fixed an issue where an incomplete character could pass through the cleaners unchanged.
- Fixed an issue where
CkCountrycould read a country out of a value that contains digits. - Fixed an issue where
CkEmailaccepted some look-alike domain names. - Fixed an issue where a JSON number too large for a double reached
CkDictionary.ValueandAtas infinity. - Fixed an issue where a JSON payload with a broken escape was refused with an internal error message.
- Fixed an issue where
CkNumber.Clamphanded back NaN when a bound was NaN.
[1.2.1]
Fixed
- Fixed an issue where a value padded with spaces past its reader's length limit was rejected; a padded "yes" reads as true again.
- Fixed an issue where
CkDictionary.Stringwrote nothing fornintandnuint, andCkSentinel.ToNulllet their zero through.
[1.2.0]
Booleans get a class of their own, and the library one boolean rule.
Added
CkBool— a realbool, a word (true,yes,on,false,no,offand their short forms) or exactly 1 or 0; anything else is unreadable, never false.FromValue,FromNumberandFromText, each with an…OrNulltwin;IsBool,IsTrue,IsFalse;Formatwith the newBoolFormatenum;Explain.CkBoolException,CkSettings.MaxBoolInputLengthandCkSettings.DefaultBoolFormat.
Changed
- Breaking for some inputs.
CkDictionary.BoolandCkText.BoolToStringread throughCkBool:2no longer reads as true, and"1.0"and"01"now do.
[1.1.0]
A validator beside every reader, an Explain on every class, the everyday helpers, and the
library on .NET 8.
Added
- Validators on every class —
CkText.IsEmpty,CkEmail.IsAddress,CkNumber.IsBetweenand the rest — for code that needs a yes or no rather than a cleaned value; the countersCkText.WordCountandCharacterCount;CkSettings.DefaultAdultAgeandMaxDecimalPlaces. Explainon every class with a reader: the reason as text,""when the value passes.CkDictionaryreads dotted paths through nested maps;At,Has,MissingKeys.CkDate.InZone,DaysBetween,StartOfMonth,EndOfMonth,Quarter,TimeAgo.CkNumber.Clamp<T>,Round,Divide.CkText.ToAscii,Initials,Between,Plural,Ordinal.CkFile.Combine,SizeToString,MediaType,ToDataUri.CkPayload.FromCsvandFromCsvMaps.CkIP.Anonymize,CkUuid.NewV7,CkCountry.Flag,CkUS.IsPoBox,CkMoney.MultiplyandTotal,CkWeb.AddQueryandRemoveQuery.CkIntl.PostalCodeandIsPostalCode.CkSettings.DefaultThrowIfInvalid, the default of everythrowIfInvalid.CkText.TruncatetakesthrowIfInvalid.
Changed
- The library targets .NET 8 instead of .NET 10, so every .NET 8 or newer application can use it.
- One package dependency,
TimeZoneConverter, so time-zone ids resolve the same on every host. - The library is licensed under MIT, with the
LICENSEfile in the package. - Breaking for some inputs. Every reader composes accents (Unicode NFC) on the way in; a
dotted
CkDictionarykey reads a nested map; andCkFile.RelativePath,CkUS.RoutingNumber,CkWeb.Url,CkIP.AddressandCkNumber.Decimalrefuse some values they accepted. CkDatereads the ISO 8601 form written with a space, with fractions and an offset.CkNumberreads a boxedHalforBigInteger;Clampfalls back to the lower bound when nofallbackis given.
Fixed
- Fixed an issue where
assumeZonewas skipped for a value whoseformatputs dashes after the clock. - Fixed an issue where
CkDate.AgeandIsAdultcounted a birth with a time on the as-of day as after it. - Fixed an issue where
CkEmail.HasDisplayNamedid not read a name before an address without brackets. - Fixed an issue where
CkText.Html,CkIntl.PhoneandCkUS.Phonecould depend on the machine's language settings.
[1.0.0]
The first release: sixteen static helper classes that read, clean, validate and convert values
on their way between the wire, the application and the database. Nothing throws unless asked —
throwIfInvalid: true raises the class's own Ck*Exception — and a value that cannot be used
comes back as the caller's fallback, an empty value or a declared sentinel instead. The
…OrNull readers answer null.
- Text and identity:
CkText,CkEmail,CkUS,CkIntl,CkCountry,CkUuid,CkIP. - Numbers, money, time and place:
CkNumber,CkMoney,CkDate,CkGeo. - Files and the web:
CkFile,CkWeb. - Payloads:
CkPayload(JSON, form bodies and query strings into one standard shape) andCkDictionary(typed values out of it).