|
That makes sense, in an odd sort of way.
And this works:
static int test()
{
int \u0066\u006F\u006F;
foo = 6;
return \u0066\u006F\u006F;
} No compiler errors, just as you'd expect.
I'd guess it's there to allow Chinese, Katakana, Persian, ... variable names and just happens to work in English as well.
But whoever found that out and used it at the coalface should be taken out and shot...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: I'd guess it's there to allow Chinese, Katakana, Persian, ... variable names and just happens to work in English as well. Maybe? I don't see much point though, since they can be used without this hexadecimal encoding step. For example, there's no problem here:
static int test()
{
int 変数 = 1;
int 整数 = 2;
return 変数 + 整数;
}
|
|
|
|
|
Yes, but I couldn't type them - they all look too similar to me. So I'd need the Unicode values or copy'n'paste to modify that code.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
sequences of underscores are also valid variable names
|
|
|
|
|
This looks like it has been written by a decompiler. At least I've seen dotPeek from JetBrains show me code like this a few times, but I don't remember the version.
Maybe someone decompiled another library to extract one (or a few) methods out of it without actually modifying the copied code?
|
|
|
|
|
And I just thought of this...
int \u0066\u006F\u006F = 34;
Console.WriteLine(nameof( \u0066\u006F\u006F));
// writes out foo
Works in C# 6.0 and above
|
|
|
|
|
Could be worse.
You'll be happy to know that I tried to assign a value to int \u263a and the IDE kvetched.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
You just need an extra 0 :
int \u0263a = 42;
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sure, but that's not an emoticon.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
strText2 = WeekdayName(myCurrentDate.DayOfWeek, False, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
I just found and fixed this in a half-dozen places whilst reviewing event logs for an Azure web app. TBF, this web app is for a strictly M-F organization, so there should be no activity at all on a Sunday...but it does seem to be happening from time to time.
btw, yes the datetime variable is a utc tz and dst adjusted datetime for the client. This code was basically just for display. I'm sure there are better ways to do it, but i'm not asking.
"Go forth into the source" - Neal Morse
|
|
|
|
|
Quote: VisualBasic.FirstDayOfWeek.Monday
That's the International Standard. I don't understand what the problem was.
|
|
|
|
|
The problem happens when the myCurrentDate variable represents a Sunday where myCurrentDate.DayOfWeek returns a 0. The WeekdayName function expects the first parameter to be between 1 and 7...0 throws an exception.
The corrected code is:
rText2 = WeekdayName(myCurrentDate.DayOfWeek + 1, False, Microsoft.VisualBasic.FirstDayOfWeek.Sunday)
"Go forth into the source" - Neal Morse
|
|
|
|
|
No, the real corrected code is:
rText2 = myCurrentDate.ToString("dddd")
Custom Date and Time Format Strings | Microsoft Docs[^]
Or, if you really want to pad the code out:
rText2 = System.Globalization.DateTimeFormatInfo.CurrentInfo.GetDayName(myCurrentDate.DayOfWeek)
The vast majority of the Microsoft.VisualBasic assembly is just there for backwards-compatibility with VB6, and should be avoided wherever possible.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you Richard! Helpful as always...I knew there had to be a better way!
"Go forth into the source" - Neal Morse
|
|
|
|
|
string isValidArticle(string article) - The Daily WTF[^]
A Zero-Day exploit in the .NET framework through the WSDL parser.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
We need a new icon for "coding horror". Perhaps a WTF with its hair standing on end?
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
I've always had this standard of code that I thought was "Microsoft quality". Granted, given the number of bugs and "features over fix" commonly found in Microsoft products, this bar was not set high.
This ... "sample", for lack of a sufficiently derogatory term, just jumps on that bar and smashes it into the ground.
How the that code ever made it past review, let alone testing, is beyond my too-early-in-the-morning-on-a-weekend comprehension.
|
|
|
|
|
It's a shame the article doesn't quite explain the problem properly.
The code is generating a verbatim string literal, so newlines in the string don't need to be encoded or escaped.
Source:
This is a perfectly valid
verbatim string literal
across multiple lines. Output:
string foo = @"This is a perfectly valid
verbatim string literal
across multiple lines.";
Unfortunately, that string literal ends up being placed in a single-line comment, which only comments out the first line.
Source:
This is a commented-out verbatim string literal.
System.Diagnostics.Process.Start("evil-code.exe");
// Output:
System.Diagnostics.Process.Start("evil-code.exe");
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Good find by the hackers, just reading the code made me really cringe, mainly because I'm nowhere near awake enough to parse it correctly. Whether it's a gross missnaming or the devs not checking what isValidURL() actually validates one can be certain oversights were made.
I'm in the middle of refactoring some css to make it clear and this article is yet another validation to striving to name things to the best of ones ability. My issue is naturally trivial in comparison and there is zero possibility of failing in such an impactful way, but clear code speaks for itself.
|
|
|
|
|
Apart from being badly named and using a global static that code is not too bad.
The code that is the real hair-raiser is the code that assumes it is safe to comment it out using a single line comment.
|
|
|
|
|
Nothing is global in .NET; also, a single static StringBuilder is not going to consume large amounts of memory.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
After finding this ultra-cool Bootstrap `DateTimePicker`, I thought I could simply select all my date-pickers by class, and apply the relevant code for the `DateTimePicker`, and I’d have elegant and working date-time pickers all over.
That was during that usual “honeymoon” period when you’ve just found a really cool hammer and can only see nails. That period passes quite quickly and then we’re left to deal with little niggly wrinkles to iron out on your new widget.
The first and biggest is that MVC “has already” turned one of my date-time inputs into a built-in browser native date picker. On Edge and Chrome the built-in picker is usable, but not good UX and somewhat unintuitive. I don’t know how other browsers present date and time pickers. If a model property is of `DateTime`, MVC scaffolds an input with type `datetime-local`, and lets the browser deal with the rest.
The code to initialize the DateTimePicker is normally simple, just call on your date-time input, like this:
$(".date-picker").datetimepicker();
Now when I did that, something weird happened. When I clicked any date-picker (input with class `date-picker`), I’d see two date-pickers: My new fancy one in the background, and overlaid on top of that, the browser date-picker – in my case Edge.
I have to first make the input a normal text input, and then the fancy DateTimePicker, for things to work as wanted, with the 3rd party date-picker in charge:
$(".date-picker").attr("type", "text");
$(".date-picker").datetimepicker();
Now I have one last “little” problem. When I click on one of my date-picklers, I get a history dropdown of recently used dates, but I suspect it is the browser’s date-picker doing this, because it drops down over my date-picker rendering it useless. Fortunately, a second click shows my date-picker without the dropdown.
"'Do what thou wilt...' is to bid Stars to shine, Vines to bear grapes, Water to seek its level; man is the only being in Nature that has striven to set himself at odds with himself."
—Aleister Crowley
|
|
|
|
|
somehow weired. Is the code correct?
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
What code? My little two lines of JS that fix things? There is no other code involved in this problem.
|
|
|
|