littlebrighter / alfred--ultimate-currency-converter

The best Alfred Workflow for Converting Currencies. Period.
MIT License
28 stars 1 forks source link

Bug in Ultimate Currency Converter default to conversion #13

Open dexamenos opened 1 year ago

dexamenos commented 1 year ago

Anonymous reported:

I believe I found a small bug. To replicate:

Set to use the getgeoapi.com API In alfred, execute currency-set-to EUR (I also set the default from to USD, not sure if that matters) Enter currency 200 GBP in Alfred Notice how the converted amount is in USD while one would expect it to be in EUR

Locally I fixed it for myself by in the e4QueryParser.php file changing the parse() function. Please see below. I didn't test and consider the implications the change would have but thought it might still be better to share than not to.

public function parse() { // Try to export informations from the user query foreach (self::$reRules AS $re => $suggestString) { if (preg_match("/^\s{$re}\s$/i", $this->query, $this->parsed)) { $this->parsed['re'] = $re; $this->parsed['reSuggest'] = $suggestString;

    // Parse from currency
    $this->from->setInput($this->parsed['from']);
    if (!$this->from->parse())
      $this->from = $this->defaultFrom;

    // Parse to currency
    $this->to->setInput($this->parsed['to']);
    if (!$this->to->parse())
      $this->to = $this->defaultTo;  // Use the default "to" currency

    // Parse amount
    $this->amount = preg_replace('/(\d+)\.(?!\d+$)/', '$1', str_replace(',', '.', $this->parsed['amount'] ?: '1'))*1;
    $this->amount = $this->amount ?: 1;

    return $this->valid = true;
  }
}
return $this->valid = false;

}

And here the diff:

--- original.php +++ modified.php @@ -13,7 +13,7 @@ // Parse to currency $this->to->setInput($this->parsed['to']); if (!$this->to->parse())

Best regards,