tim-hub / obsidian-bible-reference

Take Bible Study notes easily in the popular note-taking app Obsidian, with automatic verse and reference suggestions.
https://antioch.tech/obsidian-bible-reference/
MIT License
221 stars 41 forks source link

[Bug] (BibleGateway) Hyperlink broken when bookName contains `space` #185

Closed abbasou closed 3 months ago

abbasou commented 3 months ago

Describe the bug When using a version from BibleGateway and the Book Name contains a space (i.e. "1 Timothy," "2 Chronicles," etc.) the link to BibleGateway will be broken. This will cause formatting issues as well.

To Reproduce Steps to reproduce the behavior:

  1. Insert a reference from a BibleGateway version where the Book contains a space in the name.
  2. See error

Expected behavior The linker should replace the space with a "+" for a proper hyperlink and correct formatting.

Screenshots image image

What Device Do You Use(please complete the following information):

abbasou commented 3 months ago

So in poking around a bit, I came across the following snippet:

var BibleAPIDotComProvider = class extends BaseBibleAPIProvider {
  constructor(bibleVersion) {
    super(bibleVersion);
  }
  /**
   * Build Request Url for Bible-Api.com
   * @param bookName
   * @param chapter
   * @param verses
   * @param versionName
   */
  buildRequestURL(bookName, chapter, verses, versionName) {
    let queryString = `${bookName}+${chapter}:`.replace(/ /g, "+");
    queryString += this.convertVersesToQueryString(verses);
    this._currentQueryUrl = `${this._apiUrl}/${queryString}?translation=${versionName ? versionName : (this == null ? void 0 : this.BibleVersionKey) ? this.BibleVersionKey : ""}`;
    this.bibleGatewayUrl = this.buildBibleGatewayUrl(bookName, chapter, verses);
    return this._currentQueryUrl;
  }

and noticed the .replace function. I moved it down toward the end of the function as so: this.bibleGatewayUrl = this.buildBibleGatewayUrl(bookName, chapter, verses).replace(/ /g, "+"); and restarted Obsidian and lo and behold it worked!

tim-hub commented 3 months ago

Fix in https://github.com/tim-hub/obsidian-bible-reference/releases/tag/2.4.5

Thanks @abbasou