{"id":34218,"date":"2021-11-19T16:33:01","date_gmt":"2021-11-19T21:33:01","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=34218"},"modified":"2021-11-19T16:33:01","modified_gmt":"2021-11-19T21:33:01","slug":"unicode-and-copying-and-pasting-code","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/11\/19\/unicode-and-copying-and-pasting-code\/","title":{"rendered":"Unicode and Copying and Pasting Code"},"content":{"rendered":"<p><a href=\"https:\/\/dev.to\/glennfaison\/a-good-reason-why-you-should-not-copy-and-paste-code-1eoi\">Glenn Faison<\/a>:<\/p>\n<blockquote cite=\"https:\/\/dev.to\/glennfaison\/a-good-reason-why-you-should-not-copy-and-paste-code-1eoi\"><p>I recently saw first-hand why I should never copy and paste any code I found online (or anywhere, for that matter).<\/p>\n<p>[&#8230;]<\/p>\n<p>To cut the long story short, what looks like a <em>loose inequality<\/em> check on line #4, is deceptively an assignment operation, which reads like (<code>environment&#x1C3; = ENV_PROD<\/code>)! In JavaScript, assignment operations return the assigned value, which in this case is truthy (will be treated as true wherever a boolean value is expected).<\/p>\n<p>But isn&rsquo;t <code>environment&#x1C3;<\/code> an invalid variable name in JavaScript, you ask? It&rsquo;s complicated. You&rsquo;d be right to say an exclamation sign cannot be part of a variable name. However, the <code>&#x1C3;<\/code> you see there is in fact not the everyday exclamation sign you know. It&rsquo;s an obscure character that happens to be accepted as regular text by the JavaScript interpreter, and thus can be a valid part of a variable name.<\/p><\/blockquote>\n\n<p>This particular example is unlikely to happen in Swift, both because assignments don&rsquo;t have values and because the compiler is picky about whitespace around operators.<\/p>\n\n<p>Via <a href=\"https:\/\/twitter.com\/nicklockwood\/status\/1459473605516005376\">Nick Lockwood<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/nicklockwood\/status\/1459473605516005376\">\n<p>This is why unicode (outside of string literals) in programming languages was a mistake.<\/p>\n<p>[&#8230;]<\/p>\n<p>Support for unicode in variables adds a massive new surface for hiding security exploits in plain sight (see also: unicode urls).<\/p>\n<p>The supposed benefit of being able to use mathematical symbols for custom operators is mostly just an attractive nuisance since you can&rsquo;t type them.<\/p>\n<p>Inclusivity is good, but unicode variables offer little practical benefit to non-English speakers if the platform APIs and dominant 3rd party frameworks are not localized, and unicode is neither necessary nor sufficient to solve that (it should ideally be handled at IDE-level).<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/blog.rust-lang.org\/2021\/11\/01\/cve-2021-42574.html\">CVE-2021-42574<\/a> (via <a href=\"https:\/\/twitter.com\/dmartincy\/status\/1459492605704781838\">Daniel Mart&iacute;n<\/a>):<\/p>\n<blockquote cite=\"https:\/\/blog.rust-lang.org\/2021\/11\/01\/cve-2021-42574.html\"><p>The Rust Security Response WG was notified of a security concern affecting source code containing &ldquo;bidirectional override&rdquo; Unicode codepoints: in some cases the use of those codepoints could lead to the reviewed code being different than the compiled code.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/13\/macos-filename-homoglyphs-revisited\/\">macOS Filename Homoglyphs Revisited<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/02\/23\/big-list-of-naughty-strings\/\">Big List of Naughty Strings<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/01\/04\/fingerprinting-swift-code-using-spacecrypt\/\">Fingerprinting Swift Code Using Spacecrypt<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Glenn Faison: I recently saw first-hand why I should never copy and paste any code I found online (or anywhere, for that matter). [&#8230;] To cut the long story short, what looks like a loose inequality check on line #4, is deceptively an assignment operation, which reads like (environment&#x1C3; = ENV_PROD)! In JavaScript, assignment operations [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-11-19T21:33:12Z","apple_news_api_id":"f17888a0-f6a6-44c3-8254-5df443c92aa8","apple_news_api_modified_at":"2021-11-19T21:33:12Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A8XiIoPamRMOCVF30Q8kqqA","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[346,46,309,71,408,48,901,258],"class_list":["post-34218","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-javascript","tag-languagedesign","tag-localization","tag-programming","tag-rust-lang","tag-security","tag-swift-programming-language","tag-unicode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=34218"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34218\/revisions"}],"predecessor-version":[{"id":34219,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/34218\/revisions\/34219"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=34218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=34218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=34218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}