Skip to main content

CodeSOD: An Echo In Here in here

4 months 3 weeks ago

Tobbi sends us a true confession: they wrote this code.

The code we're about to look at is the kind of code that mixes JavaScript and PHP together, using PHP to generate JavaScript code. That's already a terrible anti-pattern, but Tobbi adds another layer to the whole thing.

if (AJAX) { <?php echo "AJAX.open(\"POST\", '/timesheets/v2/rapports/FactBCDetail/getDateDebutPeriode.php', true);"; ?> AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); AJAX.onreadystatechange = callback_getDateDebutPeriode; AJAX.send(strPostRequest); } if (AJAX2) { <?php echo "AJAX2.open(\"POST\", '/timesheets/v2/rapports/FactBCDetail/getDateFinPeriode.php', true);"; ?> AJAX2.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); AJAX2.onreadystatechange = callback_getDateFinPeriode; AJAX2.send(strPostRequest); }

So, this uses server side code to… output string literals which could have just been written directly into the JavaScript without the PHP step.

"What was I thinking when I wrote that?" Tobbi wonders. Likely, you weren't thinking, Tobbi. Have another cup of coffee, I think you need it.

All in all, this code is pretty harmless, but is a malodorous brain-fart. As for absolution: this is why we have code reviews. Either your org doesn't do them, or it doesn't do them well. Anyone can make this kind of mistake, but only organizational failures get this code merged.

[Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
Remy Porter

China Is Sending Its World-Beating Auto Industry Into a Tailspin

4 months 3 weeks ago
An anonymous reader quotes a report from Reuters: On the outskirts of this city of 21 million, a showroom in a shopping mall offers extraordinary deals on new cars. Visitors can choose from some 5,000 vehicles. Locally made Audis are 50% off. A seven-seater SUV from China's FAW is about $22,300, more than 60% below its sticker price. These deals -- offered by a company called Zcar, which says it buys in bulk from automakers and dealerships -- are only possible because China has too many cars. Years of subsidies and other government policies have aimed to make China a global automotive power and the world's electric-vehicle leader. Domestic automakers have achieved those goals and more -- and that's the problem. China has more domestic brands making more cars than the world's biggest car market can absorb because the industry is striving to hit production targets influenced by government policy, instead of consumer demand, a Reuters examination has found. That makes turning a profit nearly impossible for almost all automakers here, industry executives say. Chinese electric vehicles start at less than $10,000; in the U.S., automakers offer just a few under $35,000. Most Chinese dealers can't make money, either, according to an industry survey published last month, because their lots are jammed with excess inventory. Dealers have responded by slashing prices. Some retailers register and insure unsold cars in bulk, a maneuver that allows automakers to record them as sold while helping dealers to qualify for factory rebates and bonuses from manufacturers. Unwanted vehicles get dumped onto gray-market traders like Zcar. Some surface on TikTok-style social-media sites in fire sales. Others are rebranded as "used" -- even though their odometers show no mileage -- and shipped overseas. Some wind up abandoned in weedy car graveyards. These unusual practices are symptoms of a vastly oversupplied market -- and point to a potential shakeout mirroring turmoil in China's property market and solar industry, according to many industry figures and analysts. They stem from government policies that prioritize boosting sales and market share -- in service of larger goals for employment and economic growth -- over profitability and sustainable competition. Local governments offer cheap land and subsidies to automakers in exchange for production and tax-revenue commitments, multiplying overcapacity across the country.

Read more of this story at Slashdot.

BeauHD