Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TitleCaser errors out (full disclosure: BBT uses it in possibly inappropriate ways) #35

Closed
retorquere opened this issue Feb 18, 2017 · 3 comments

Comments

@retorquere
Copy link
Collaborator

So, the full disclosure first: BBT uses the titlecaser outside the scope of the citation processor running, so it's fully possible that I'm calling it with an illegitimate state, thereby causing the breakage. I've called the citeproc titlecaser in this way for a long time though, and it has always worked before.

Here's what I'm actually doing:

var makeRegExp, state, titleCase;

makeRegExp = function(lst) {
  return new RegExp('(?:(?:[?!:]*\\s+|-|^)(?:' + lst.slice().join('|') + ')(?=[!?:]*\\s+|-|$))', 'g');
};

state = {
  opt: {
    lang: 'en'
  },
  locale: {
    en: {
      opts: {
        'skip-words': CSL.SKIP_WORDS,
        'skip-words-regexp': makeRegExp(CSL.SKIP_WORDS)
      }
    }
  }
};

titleCase = function(text) {
  return CSL.Output.Formatters.title(state, text);
};

console.log(titleCase("/ ' '"));

This has always worked splendidly for me, but with this particular string it errors out with

var origChar = config.doppel.origStrings[quotePos+1].slice(0, 1);
TypeError: Cannot read property 'slice' of undefined

here: https://github.com/Juris-M/citeproc-js/blob/master/citeproc.js#L14984

I've inspected (what I think is ) the relevant state of the function at that point when it breaks, and I see this:

CSL: {"config.doppel.origStrings":["","","",""],"quotePos":2,"config.quoteState":[{"opener":" \"","closer":"'","positions":2}],"i":0}

While I have zero clues on what doppelString is doing, if I replace

var quotePos = config.quoteState[i].pos;

with

var quotePos = (typeof config.quoteState[i].pos == "number") ? config.quoteState[i].pos : config.quoteState[i].positions;

all my tests pass.

(as an aside, it'd be very useful to me if makeRegExp were exposed as a method)

@fbennett
Copy link
Contributor

Sorry for the long delay in responding. Is it safe to close this, or is the TitleCase-r still causing headaches for you?

@retorquere
Copy link
Collaborator Author

I think this must be fixed because I use the titlecaser in my BBT5 work and I've removed the source patches I had in place. I think this can be closed; if new stuff crops up I'll open a new one.

No apologies expected or necessary; I appreciate whatever effort you can put into citeproc.

@fbennett
Copy link
Contributor

Good to hear!

@fbennett fbennett reopened this Aug 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants