Skip to content

Unit Converter: Fahrenheit input bypasses absolute-zero validation and yields negative Kelvin #11103

Open

Description

@Poojax21

Summary

public/Unit-Converter/script.js validates below-absolute-zero inputs only when the source unit is Kelvin or Celsius. Selecting Fahrenheit as the source unit skips both guards entirely, so physically impossible temperatures convert successfully into negative Kelvin - contradicting the validation the same form enforces for the other two units.

Static-analysis finding based on reading branch Main; not executed here.

Location

  • File: public/Unit-Converter/script.js
  • Functions: validateInput() (guards at ~lines 303-325) and convertTemperature() (~lines 349-371)
if(fromUnit.value==="kelvin" && value<0){
  return { valid:false, message:"Temperature cannot be below 0 Kelvin" };
}
if(fromUnit.value==="celsius" && value<-273.15){
  return { valid:false, message:"Temperature cannot be below -273.15 C" };
}

There is no corresponding guard for fromUnit.value==="fahrenheit" (-459.67 F = absolute zero), while convertTemperature() processes any Fahrenheit value ((value-32)*5/9, then +273.15 for Kelvin output).

Trigger / Reproduction

Based on source reading:

  1. Category: Temperature, From: Fahrenheit, To: Kelvin.
  2. Enter -500 (the input filter allows -).
  3. Validation passes (no Fahrenheit branch).
  4. Output: (-500-32)*5/9 + 273.15 = -22.41 K.

Expected Behavior

The same physical state must be rejected regardless of source unit: entering -22 K directly shows "Temperature cannot be below 0 Kelvin", so converting to that identical value from Fahrenheit should be rejected too.

Actual Behavior

A negative Kelvin result is displayed as a successful conversion.

Impact

The converter's core purpose (physically valid conversions) silently breaks for one of its three supported units; users receive impossible values with no warning.

Suggested Direction

Convert the input to Kelvin first inside validateInput() (or add the missing Fahrenheit guard < -459.67) so the physical limit is enforced once for all units instead of per-unit in the input scale.

I'd like to take this up - requesting assignment per GSSoC'26 first-come-first-serve guidelines (@Poojax21).

Activity

  1. github-actions commented on Aug 26, 2026

    @github-actions
    Contributor

    Thank you for raising this issue! We'll look into it as soon as possible. Please ensure that the issue is not duplicate, and you read CONTRIBUTING.md carefully. Your contributions are highly appreciated! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions